File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ add_subdirectory(letter-comb)
55add_subdirectory (lgc)
66add_subdirectory (parentheses)
77add_subdirectory (remove-duplicates-from-sorted)
8+ add_subdirectory (strong-pass-check-2)
89add_subdirectory (validate-ip)
Original file line number Diff line number Diff line change 1+ set (CMAKE_C_STANDARD 99)
2+
3+ add_executable (strong-pass-check-2 main.c)
Original file line number Diff line number Diff line change 1+ #include <ctype.h>
2+ #include <stdbool.h>
3+ #include <stdio.h>
4+ #include <string.h>
5+
6+ static bool isPermittedSpecial (char ch )
7+ {
8+ switch (ch ) {
9+ case '!' :
10+ case '@' :
11+ case '#' :
12+ case '$' :
13+ case '%' :
14+ case '^' :
15+ case '&' :
16+ case '*' :
17+ case '(' :
18+ case ')' :
19+ case '-' :
20+ case '+' :
21+ return true;
22+ default :
23+ return false;
24+ }
25+ }
26+
27+ bool strongPasswordCheckerII (char * password )
28+ {
29+ if (strlen (password ) < 8 ) {
30+ return false;
31+ }
32+
33+ char last_ch = '\0' ;
34+
35+ bool has_lower = false;
36+ bool has_upper = false;
37+ bool has_digit = false;
38+ bool has_special = false;
39+ for (const char * ch = password ; * ch != '\0' ; ++ ch ) {
40+ if (* ch == last_ch ) {
41+ return false;
42+ }
43+ last_ch = * ch ;
44+ if (islower (* ch )) {
45+ has_lower = true;
46+ continue ;
47+ }
48+ if (isupper (* ch )) {
49+ has_upper = true;
50+ continue ;
51+ }
52+ if (isdigit (* ch )) {
53+ has_digit = true;
54+ continue ;
55+ }
56+ if (isPermittedSpecial (* ch )) {
57+ has_special = true;
58+ continue ;
59+ }
60+ }
61+
62+ return has_lower && has_upper && has_digit && has_special ;
63+ }
64+
65+ /* https://leetcode.com/problems/strong-password-checker-ii/ */
66+ int main (void )
67+ {
68+ printf ("d: %d\n" , strongPasswordCheckerII ("IloveLe3tcode!" ));
69+ return 0 ;
70+ }
You can’t perform that action at this time.
0 commit comments