-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (45 loc) · 1.27 KB
/
main.cpp
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
class Solution {
public:
bool strongPasswordCheckerII(string password) {
if (password.size() < 8) return false;
bool has_lower = false;
for (char c : password) {
if (islower(c)) {
has_lower = true;
break;
}
}
if (!has_lower) return false;
bool has_upper = false;
for (char c : password) {
if (isupper(c)) {
has_upper = true;
break;
}
}
if (!has_upper) return false;
bool has_digit = false;
for (char c : password) {
if (isdigit(c)) {
has_digit = true;
break;
}
}
if (!has_digit) return false;
bool has_special = false;
string special = "!@#$%^&*()-+";
unordered_set<char> special_chars;
for (char c : special) special_chars.insert(c);
for (char c : password) {
if (special_chars.count(c)) {
has_special = true;
break;
}
}
if (!has_special) return false;
for (int i = 1; i < password.size(); ++i) {
if (password[i] == password[i - 1]) return false;
}
return true;
}
};