题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <stdio.h> #include <string.h> #include <ctype.h> int main() { char str[301]={0}; scanf("%s",str); int len; len=strlen(str); int zf=0; int lf=0; int habc=0; int hupp=0; int hlow=0; int hnum=0; int hnum1=0; int hnumn=0; int fnum=0; int fnum1=0; int fnumn=0; int jl=0; if(len<=4) {lf=5;} else if(len<=7) { lf=10; } else if(len>=8) { lf=25; } for(int i=0;i<len;i++) { if(isalpha(str[i])) { habc++; if(isupper(str[i])) { hupp++; } else if(islower(str[i])) { hlow++; } } else if(isdigit(str[i])) { hnum++; } else if(str[i]!=EOF) { fnum++; } } if(habc>0) { if((hupp>0)&&(hlow>0)) { zf=zf+20; } else { zf=zf+10; } } if(hnum>0) { if(hnum==1) { zf=zf+10; } else { zf=zf+20; } } if(fnum>0) { if(fnum==1) { zf=zf+10; } else { zf=zf+25; } } if(habc>0&&hnum>0) { if(fnum>0) { if(hupp>0&&hlow>0) { zf=zf+5; } else { zf=zf+3; } } else { zf=zf+2; } } zf=zf+lf; if(zf>=90){printf("VERY_SECURE");} else if(zf>=80){printf("SECURE");} else if(zf>=70){printf("VERY_STRONG");} else if(zf>=60){printf("STRONG");} else if(zf>=50){printf("AVERAGE");} else if(zf>=25){printf("WEAK");} else {printf("VERY_WEAK");} }