-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeft_Right_Hand_Word.cpp
More file actions
111 lines (104 loc) · 2.18 KB
/
Left_Right_Hand_Word.cpp
File metadata and controls
111 lines (104 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "stdafx.h"
#include "iostream"
#include "vector"
#include "string"
#include "map"
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <stack>
#include <sstream>
#include <iomanip>
#include <random>
#include <assert.h>
#include <iterator>
#include <queue>
#include <math.h>
#include <vector>
#include <set>
using namespace std;
enum fingerType{LEFT, RIGHT, MIX};
char leftC[256]={0};
char rightC[256]={0};
fingerType getFingerType(string s)
{
fingerType toReturn=MIX;
char *standard=NULL;
for(int i=0;i<s.size();i++)
{
if(standard==NULL)
{
if(leftC[s[i]])
{
standard=leftC;
toReturn=LEFT;
}
else
{
standard=rightC;
toReturn=RIGHT;
}
}
else
{
if(standard[s[i]]==0)return MIX;
}
}
return toReturn;
}
void getLargestSmallest(vector<string> s)
{
string leftSmallest="", leftLargest="";
int leftSmallestLength=10000, leftLargestLength=0;
string rightSmallest="", rightLargest="";
int rightSmallestLength=10000, rightLargestLength=0;
for(int i=0;i<s.size();i++)
{
fingerType ft=getFingerType(s[i]);
if(ft==MIX)continue;
else if(ft==LEFT)
{
if(s[i].size()>leftLargestLength)
{
leftLargest=s[i];
leftLargestLength=s[i].size();
}
if(s[i].size()<leftSmallestLength)
{
leftSmallest=s[i];
leftSmallestLength=s[i].size();
}
}
else
{
if(s[i].size()>rightLargestLength)
{
rightLargest=s[i];
rightLargestLength=s[i].size();
}
if(s[i].size()<rightSmallestLength)
{
rightSmallest=s[i];
rightSmallestLength=s[i].size();
}
}
}
cout<<leftSmallest<<" "<<leftLargest<<endl;
cout<<rightSmallest<<" "<<rightLargest<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
string leftSS="qwerasdftgzxcvb";
string rightSS="uiopjklm;";
for(int i=0;i<leftSS.size();i++)leftC[leftSS[i]]=1;
for(int i=0;i<rightSS.size();i++)rightC[rightSS[i]]=1;
vector<string> result;
result.push_back("");
result.push_back("as");
result.push_back("qwer");
result.push_back("dfj");
result.push_back("uiopm");
result.push_back("kli");
getLargestSmallest(result);
return 0;
}