-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3136.cpp
More file actions
44 lines (44 loc) · 1.25 KB
/
3136.cpp
File metadata and controls
44 lines (44 loc) · 1.25 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
class Solution {
public:
bool isVowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return true;
if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') return true;
return false;
}
bool isConsonant(char c) {
if (isVowel(c)) return false;
int n = c - 'a';
if (n >= 0 && n < 26) return true;
n = c - 'A';
if (n >= 0 && n < 26) return true;
return false;
}
bool isDigitAlpha(char c) {
int n = c - 'a';
if (n >= 0 && n < 26) return true;
n = c - 'A';
if (n >= 0 && n < 26) return true;
n = c - '0';
if (n >= 0 && n < 10) return true;
return false;
}
bool isValid(string word) {
int cnt = 0;
bool isDigitAlphaOnly = true;
bool hasVowel = false;
bool hasConsonant = false;
for (auto& c : word) {
if (isVowel(c)) {
hasVowel = true;
}
if (isConsonant(c)) {
hasConsonant = true;
}
cnt++;
if (!isDigitAlpha(c)) {
isDigitAlphaOnly = false;
}
}
return cnt >= 3 && isDigitAlphaOnly && hasVowel && hasConsonant;
}
};