题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <stdio.h> #include <string.h> #include "ctype.h" int three_type(char* str) { int upper,lower,other,digit; upper=lower=other=digit=0; int len = strlen(str); for(int i=0;i<len;i++) { if(islower(str[i])){ lower =1; } else if(isupper(str[i])){ upper =1; } else if(isdigit(str[i])){ digit =1; } else{ other = 1; } } if(upper+lower+other+digit>=3){ return 1; } else return 0; } int _double(char* str) { int len = strlen(str); for(int i=0;i<len-2;i++) { for(int j=i+1;j<len-2;j++) { if(str[i]==str[j]&&str[i+1]==str[j+1]&&str[i+2]==str[j+2]) { return 0; } } } return 1; } int main() { char pswd[100]; int flag_isok; int len; while(scanf("%s",pswd)!=EOF) { flag_isok = 1; len = strlen(pswd); if(len<8) { flag_isok = 0; } else if(_double(pswd)==0) { flag_isok = 0; } else if(three_type(pswd)==0) { flag_isok = 0; } if(flag_isok) { printf("OK\n"); } else{ printf("NG\n"); } } return 0; }