题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <stdio.h> #include <strings.h> void score(char str[]) { int len; int flag1=0; int flag2=0; int num=0; int sign=0; int score,score1,score2,score3,score4,score5; len=strlen(str); for(int i=0; i<len; i++){ if (str[i]>='a' && str[i]<='z') { flag1=1; }else if(str[i]>='A' && str[i]<='Z') { flag2=1; }else if (str[i]>='0' && str[i]<='9') num++; else sign++; } if(len<5) score1=5; else if(len>4 && len <8) score1=10; else score1=25; if((flag1+flag2)==0) score2=0; else if((flag1+flag2)==1) score2=10; else score2=20; if(num==0) score3=0; else if(num==1) score3=10; else score3=20; if(sign==0) score4=0; else if(sign==1) score4=10; else score4=25; if((flag1+flag2)>1 && num>0 && sign>0) score5=5; else if((flag1+flag2)==1 && num>0 && sign>0) score5=3; else if(sign==0 && num>0 && (flag1+flag2)>0) score5=2; score=score1+score2+score3+score4+score5; if (score >= 90) { printf("VERY_SECURE"); } else if (score >= 80 && score < 90) { printf("SECURE"); } else if (score >= 70 && score < 80) { printf("VERY_STRONG"); } else if (score >= 60 && score < 70) { printf("STRONG"); } else if (score >= 50 && score < 60) { printf("AVERAGE"); } else if (score >= 25 && score < 50) { printf("WEAK"); } else if (score >= 0 && score < 25) { printf("VERY_WEAK"); } } int main() { char str[300]; while (~scanf("%s", str)) { score(str); } return 0; }