密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分。
一、密码长度:
5 分: 小于等于4 个字符
10 分: 5 到7 字符
25 分: 大于等于8 个字符
二、字母:
0 分: 没有字母
10 分: 全都是小(大)写字母
20 分: 大小写混合字母
三、数字:
0 分: 没有数字
10 分: 1 个数字
20 分: 大于1 个数字
四、符号:
0 分: 没有符号
10 分: 1 个符号
25 分: 大于1 个符号
五、奖励:
2 分: 字母和数字
3 分: 字母、数字和符号
5 分: 大小写字母、数字和符号
最后的评分标准:
>= 90: 非常安全
>= 80: 安全(Secure)
>= 70: 非常强
>= 60: 强(Strong)
>= 50: 一般(Average)
>= 25: 弱(Weak)
>= 0: 非常弱
对应输出为:
VERY_SECURE
SECURE,
VERY_STRONG,
STRONG,
AVERAGE,
WEAK,
VERY_WEAK,
解题思路:
非常简单= =,不要被题目吓到
#include<iostream>
using namespace std;
int main(){
string str;
while(cin>>str){
int n = str.size();
int score=0;
//密码长度
if(n>0&&n<=4) score+=5;
else if(n>=5&&n<8) score+=10;
else if(n>=8) score+=25;
//字母 数组 符号统计
int caseCnt=0,CaseCnt=0,numCnt=0,charCnt=0;
for(int i=0;i<n;i++){
if(str[i]>='A'&&str[i]<='Z') CaseCnt++;
else if(str[i]>='a'&&str[i]<='z') caseCnt++;
else if(str[i]>='0'&&str[i]<='9') numCnt++;
else charCnt++;
}
//字母
if((caseCnt==0&&CaseCnt!=0)||(caseCnt!=0&&CaseCnt==0))
score+=10;
else if(caseCnt!=0&&CaseCnt!=0)
score+=20;
//数字
if(numCnt==1)
score+=10;
else if(numCnt>1)
score+=20;
//字符
if(charCnt==1)
score+=10;
else if(charCnt>1)
score+=25;
//奖励
if(numCnt>0&&caseCnt>0&&CaseCnt>0&&charCnt>0)
score+=5;
else if(numCnt>0&&(caseCnt>0||CaseCnt>0)&&charCnt>0)
score+=3;
else if(numCnt>0&&(caseCnt>0||CaseCnt>0))
score+=2;
if(score>=90)
cout<<"VERY_SECURE"<<endl;
else if(score>=80)
cout<<"SECURE"<<endl;
else if(score>=70)
cout<<"VERY_STRONG"<<endl;
else if(score>=60)
cout<<"STRONG"<<endl;
else if(score>=50)
cout<<"AVERAGE"<<endl;
else if(score>=25)
cout<<"WEAK"<<endl;
else
cout<<"VERY_WEAK"<<endl;
}
}