题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <iostream> using namespace std; int main() { string s; cin>>s; int len=s.size(); int s_len=0;//长度分数 int s_alpha=0;//字母分数 int count_upper=0;//小写字母个数 int count_lower=0;//大写字母个数 int s_num=0; int count_num=0; int s_symbol=0; int count_symbol=0; int award=0; if(len<=4)s_len=5;else if(len>4&&len<8)s_len=10;else s_len=25; for(auto ch:s){ if(ch>='a'&&ch<='z')count_lower++; else if(ch>='A'&&ch<='Z')count_upper++; else if(isdigit(ch))count_num++; else count_symbol++; } if(count_lower*count_upper==0)s_alpha=10; else if(count_lower*count_upper!=0)s_alpha=20; if(count_num==1)s_num=10; else if(count_num>1)s_num=20; if(count_symbol==1)s_symbol=10; else if(count_symbol>1)s_symbol=25; if(s_alpha!=0&&s_num!=0){ award=2; if(s_symbol!=0){ award=3; if(count_lower*count_upper!=0) award=5; } } int socer=s_alpha+s_num+s_len+s_symbol+award; if(socer>=90)cout<<"VERY_SECURE"<<endl; else if(socer>=80)cout<<"SECURE"<<endl; else if(socer>=70)cout<<"VERY_STRONG"<<endl; else if(socer>=60)cout<<"STRONG"<<endl; else if(socer>=50)cout<<"AVERAGE"<<endl; else if(socer>=25)cout<<"WEAK"<<endl; else if(socer>=0)cout<<"VERY_WEAK"<<endl; } // 64 位输出请用 printf("%lld")