【十二题解】 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include<stdio.h>
int main(){
char a[300]={0};
while(scanf("%s",a)!=EOF){
int all;
int lenth =0;
int up=0, down=0, num=0, sign=0, award=0, len=0;
for(int i=0; a[i] != '\0'; lenth++, i++){
if(a[i]>='a' && a[i]<='z')down++;
if(a[i]>='A' && a[i]<='Z')up++;
if(a[i]>='0' && a[i]<='9')num++;
if((a[i]<'0' || a[i]>'9') && (a[i]<'a' || a[i]>'z') && (a[i]<'A' || a[i]>'Z'))sign++;
}
if(up && num && down && sign){
award = 5;
}
else if((up||down) && num && sign){
award = 3;
}
else if((up||down) && num){
award = 2;
}
if(lenth<=4){
len= 5;
}
else if(lenth>=5 && lenth <=7){
len= 10;
}
else{
len= 25;
}
int alp;
if(up && down){
alp = 20;
}
else if(up || down){
alp = 10;
}
else{
alp = 0;
}
int number;
if(num>=2){
number = 20;
}
else if(num == 1){
number = 10;
}
else{
number = 0;
}
int si ;
if(sign>=2){
si = 25;
}
else if(sign == 1){
si = 10;
}
else{
si = 0;
}
all = len+alp+si+award+number;
if(all >= 90){
printf("VERY_SECURE\n");
}
else if(all >= 80){
printf("SECURE\n");
}
else if(all >= 70){
printf("VERY_STRONG\n");
}
else if(all >= 60){
printf("STRONG\n");
}
else if(all >= 50){
printf("AVERAGE\n");
}
else if(all >= 25){
printf("WEAK\n");
}
else{
printf("VERY_WEAK\n");
}
}
}