题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include "stdio.h"
#include "string.h"
void print(int num)
{
if(num>=90) printf("VERY_SECURE\n");
else if(num>=80) printf("SECURE\n");
else if(num>=70) printf("VERY_STRONG\n");
else if(num>=60) printf("STRONG\n");
else if(num>=50) printf("AVERAGE\n");
else if(num>=25) printf("WEAK\n");
else if(num>=0) printf("VERY_WEAK\n");
}
int main()
{
char buf[300];
while(scanf("%s",buf)!=EOF)
{
char num = 0;
int len = strlen(buf);
char numb=0,llet=0,blet=0,fh=0;
if(len>=8) num+=25;
else if(len>=5 && len<=7) num+=10;
else if(len<=4) num+=5;
for(int i=0;i<len;i++)
{
if(buf[i]>='0' && buf[i]<='9') numb++;
else if(buf[i]>='a' && buf[i]<='z') llet++;
else if(buf[i]>='A' && buf[i]<='Z') blet++;
else if(buf[i]>=0x21 && buf[i]<=0x2f) fh++;
else if(buf[i]>=0x3a && buf[i]<=0x40) fh++;
else if(buf[i]>=0x5b && buf[i]<=0x60) fh++;
else if(buf[i]>=0x7b && buf[i]<=0x7e) fh++;
}
if(numb>1)num+=20;
else if(numb==1) num+=10;
if(fh>1)num+=25;
else if(fh==1) num+=10;
if(llet>=1 && blet>=1)num+=20;
else if(llet>=1 || blet>=1) num+=10;
if(llet>=1 && blet>=1 && fh>=1 && numb>=1)num+=5;
else if((llet>=1 || blet>=1) && fh>=1 && numb>=1) num+=3;
else if((llet>=1 || blet>=1) && numb>=1) num+=2;
print(num);
memset(buf, '\0', len);
}
return 0;
}
查看10道真题和解析
OPPO公司福利 1273人发布