题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <iostream>
using namespace std;
int main() {
string s;
getline(cin, s);
int l = 0;
int num_number = 0;
int num_alb_low = 0;
int num_alb_high = 0;
int num_symbol = 0;
//长度
if(s.size()==0){
cout<<"Very_Weak";
return 0;
}
if (s.size() <= 4) {
l += 5;
} else if (s.size() >= 5 && s.size() <= 7) {
l += 10;
} else {
l += 25;
}
for (auto x : s) {
if (x >= '0' && x <= '9') {
num_number++;
continue;
}
if (x >= 'a' && x <= 'z') {
num_alb_low++;
continue;
}
if (x >= 'A' && x <= 'Z') {
num_alb_high++;
continue;
}
if ((x >= '!' && x <= '/') || (x >= ':' && x <= '@') || (x >= '[' &&
x <= '`') || (x >= '{' && x <= '~')) {
num_symbol++;
continue;
}
}
//数字
if (num_number == 0) {
} else if (num_number == 1) {
l += 10;
} else {
l += 20;
}
//字母
if(num_alb_high+num_alb_low==0){
}else if((num_alb_low >=1 &&num_alb_high==0)|| (num_alb_high >=1&&num_alb_low==0)){
l += 10;
}else if(num_alb_low>=1&&num_alb_high>=1){
l+=20;
}
//符号
if (num_symbol == 0) {
} else if (num_symbol == 1) {
l += 10;
} else {
l += 25;
}
//奖励
if (num_alb_low >= 1 && num_alb_high >= 1 && num_number >= 1 &&
num_symbol >= 1) {
l += 5;
} else {
if ((num_alb_high + num_alb_low) >= 1 && num_number >= 1 && num_symbol >= 1) {
l += 3;
} else {
if ((num_alb_high + num_alb_low) >= 1 && num_number >= 1) {
l += 2;
}
}
}
if (l >= 90) {
cout << "VERY_SECURE";
} else if (l >= 80) {
cout << "SECURE";
} else if (l >= 70) {
cout << "VERY_STRONG";
} else if (l >= 60) {
cout << "STRONG";
} else if (l >= 50) {
cout << "AVERAGE";
} else if (l >= 25) {
cout << "WEAK";
} else if (l >= 0) {
cout << "VERY_WEAK";
}
}
// 64 位输出请用 printf("%lld")
又臭又长
阿里巴巴公司氛围 653人发布

查看30道真题和解析