题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include<stdio.h>
#include<string.h>
int main(void)
{
char str[301];
scanf("%s",&str);
int score=0;
int len=strlen(str);
if(len<=4)
{
score+=5;
}
else if(len>=5&&len<=7)
{
score+=10;
}
else if(len>=8)
{
score+=25;
}
int flag1=0;
int flag2=0;
int flag3=0;
int flag4=0;
for(int i=0;i<len;i++)
{
if(str[i]>='a'&&str[i]<='z')
{
flag1++;
}
if(str[i]>='A'&&str[i]<='Z')
{
flag2++;
}
if(str[i]>='0'&&str[i]<='9')
{
flag3++;
}
if (((str[i] >= 0x21) && (str[i] <= 0x2F)) || ((str[i] >= 0x3A) && (str[i] <= 0x40)) || ((str[i] >= 0x5B) && (str[i] <= 0x60)) || ((str[i] >= 0x7B) && (str[i] <= 0x7E)))
{
flag4++;
}
}
if((flag1==0&&flag2!=0)||(flag1!=0&&flag2==0))
{
score+=10;
}
else if(flag1!=0&&flag2!=0)
{
score+=20;
}
if(flag3==1)
{
score+=10;
}
else if(flag3>1)
{
score+=20;
}
if(flag4==1)
{
score+=10;
}
else if(flag4>1)
{
score+=25;
}
if(flag1!=0&&flag2!=0&&flag3!=0&&flag4!=0)
{
score+=5;
}
else if(flag4!=0&&flag3!=0&&(flag1==0&&flag2!=0)||(flag1!=0&&flag2==0))
{
score+=3;
}
else if(flag4==0&&!(flag1==0&&flag2==0)&&flag3!=0)
{
score+=2;
}
char S[50];
if(score>=90)
{
strcpy(S,"VERY_SECURE");
}
else if(score>=80&&score<90)
{
strcpy(S,"SECURE");
}
else if(score>=70&&score<80)
{
strcpy(S,"VERY_STRONG");
}
else if(score>=60&&score<70)
{
strcpy(S,"STRONG");
}
else if(score>=50&&score<60)
{
strcpy(S,"AVERAGE");
}
else if(score>=25&&score<50)
{
strcpy(S,"WEAK");
}
else if(score>=0&&score<25)
{
strcpy(S,"VERY_WEAK");
}
printf("%s",S);
return 0;
}
#include<string.h>
int main(void)
{
char str[301];
scanf("%s",&str);
int score=0;
int len=strlen(str);
if(len<=4)
{
score+=5;
}
else if(len>=5&&len<=7)
{
score+=10;
}
else if(len>=8)
{
score+=25;
}
int flag1=0;
int flag2=0;
int flag3=0;
int flag4=0;
for(int i=0;i<len;i++)
{
if(str[i]>='a'&&str[i]<='z')
{
flag1++;
}
if(str[i]>='A'&&str[i]<='Z')
{
flag2++;
}
if(str[i]>='0'&&str[i]<='9')
{
flag3++;
}
if (((str[i] >= 0x21) && (str[i] <= 0x2F)) || ((str[i] >= 0x3A) && (str[i] <= 0x40)) || ((str[i] >= 0x5B) && (str[i] <= 0x60)) || ((str[i] >= 0x7B) && (str[i] <= 0x7E)))
{
flag4++;
}
}
if((flag1==0&&flag2!=0)||(flag1!=0&&flag2==0))
{
score+=10;
}
else if(flag1!=0&&flag2!=0)
{
score+=20;
}
if(flag3==1)
{
score+=10;
}
else if(flag3>1)
{
score+=20;
}
if(flag4==1)
{
score+=10;
}
else if(flag4>1)
{
score+=25;
}
if(flag1!=0&&flag2!=0&&flag3!=0&&flag4!=0)
{
score+=5;
}
else if(flag4!=0&&flag3!=0&&(flag1==0&&flag2!=0)||(flag1!=0&&flag2==0))
{
score+=3;
}
else if(flag4==0&&!(flag1==0&&flag2==0)&&flag3!=0)
{
score+=2;
}
char S[50];
if(score>=90)
{
strcpy(S,"VERY_SECURE");
}
else if(score>=80&&score<90)
{
strcpy(S,"SECURE");
}
else if(score>=70&&score<80)
{
strcpy(S,"VERY_STRONG");
}
else if(score>=60&&score<70)
{
strcpy(S,"STRONG");
}
else if(score>=50&&score<60)
{
strcpy(S,"AVERAGE");
}
else if(score>=25&&score<50)
{
strcpy(S,"WEAK");
}
else if(score>=0&&score<25)
{
strcpy(S,"VERY_WEAK");
}
printf("%s",S);
return 0;
}