-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path520.cpp
More file actions
30 lines (30 loc) · 832 Bytes
/
Copy path520.cpp
File metadata and controls
30 lines (30 loc) · 832 Bytes
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
class Solution {
public:
bool detectCapitalUse(string word) {
if(word.length()==1) return true;
int case_num = -1;
if(isupper(word[0]) && isupper(word[1])) case_num = 1;
else if(islower(word[0])) case_num = 2;
else if(isupper(word[0]) && islower(word[1])) case_num = 3;
else return false;
if(case_num == 1){
for(int i=0; i<word.length(); i++){
if(islower(word[i])) return false;
}
return true;
}
else if(case_num == 2){
for(int i=0; i<word.length(); i++){
if(isupper(word[i])) return false;
}
return true;
}
else{
for(int i=1; i<word.length(); i++){
if(isupper(word[i])) return false;
}
return true;
}
return false;
}
};