题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
细心就行了
#include<iostream> #include<string> #include <cstdio> using namespace std; int main(){ string str; while(getline(cin,str)){ int len=str.size(); int score=0; //1密码长度 if(len<=4) score+=5; else if(len>=5&&len<=7) score+=10; else if(len>=8)score+=25; //字母 int small_char=0; int big_char=0; for(int i=0;i<len;i++){ if(islower(str[i])) small_char++; else if(isupper(str[i])) big_char++; } //密码里的字母全都是小写字母 if(small_char==0&&big_char==0) score+=0; else if((small_char!=0&&big_char==0)||(small_char==0&&big_char!=0)) score+=10; else if(small_char!=0&&big_char!=0) score+=20; int letternum=small_char+big_char; //数字 int num_dg=0; for(int i=0;i<len;i++){ if(isdigit(str[i])) num_dg++; } if(num_dg==0) score+=0; else if(num_dg==1) score+=10; else if(num_dg>1)score+=20; //符号 int fuhao_num; fuhao_num=len-small_char-big_char-num_dg; if(fuhao_num==0) score+=0; else if(fuhao_num==1) score+=10; else if(fuhao_num>1)score+=25; //奖励(只能选符合最多的那种奖励) int pay1=0,pay2=0,pay3=0; if(letternum!=0&&num_dg!=0) { pay1=2; } if(letternum!=0&&num_dg!=0&&fuhao_num!=0) { pay2=3;; } if(small_char!=0&&big_char!=0&&num_dg!=0&&fuhao_num!=0) { pay3=5; } int maxpay=max(max(pay1,pay2),pay3); score+=maxpay; //最后评分 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 if(score>=0) cout<<"VERY_WEAK"<<endl; } system("pause"); return 0; }