-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path500. Keyboard Row
80 lines (59 loc) · 1.6 KB
/
500. Keyboard Row
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
class Solution {
public:
int chk1(char c1 )
{
return c1=='q' || c1=='w' || c1=='e' || c1=='r' || c1=='t' || c1=='y' || c1=='u' || c1=='i' || c1=='o' || c1=='p';
}
int chk2(char c1)
{
return c1=='a' || c1=='s' || c1=='d' || c1=='f' || c1=='g' || c1=='h' || c1=='j' || c1=='k' || c1=='l';
}
int chk3(char c1){
return c1=='z' || c1=='x' || c1=='c' || c1=='v' || c1=='b' || c1=='n' || c1=='m';
}
vector<string> findWords(vector<string>& words) {
vector<string> v;
for(int i=0; i<words.size(); i++)
{
string str=words[i];
bool p=true;
for(int j=0; j<str.size(); j++)
{
if(chk1(tolower(str[j]))==0)
{
p=false;
break;
}
}
if(p==false)
{
p=true;
for(int j=0; j<str.size(); j++)
{
if(chk2(tolower(str[j]))==0)
{
p=false;
break;
}
}
}
if(p==false)
{
p=true;
for(int j=0; j<str.size(); j++)
{
if(chk3(tolower(str[j]))==0)
{
p=false;
break;
}
}
}
if(p==true)
{
v.push_back(words[i]);
}
}
return v;
}
};