题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
// HJ87-2 密码强度等级.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 #include<iostream> #include<bits/stdc++.h> using namespace std; int main() { string s; while (getline(cin, s)) { int len = s.size(), up = 0, low = 0, num = 0, ch = 0,score=0; int ss = 0, sa = 0, sn = 0, sc = 0, so = 0; if (len <= 4) { ss = 5; } else if (len >= 5 && len <= 7) { ss = 10; } else if (len >= 8) { ss = 25; } for (int i = 0; i < s.size(); i++) { if (isupper(s[i])) { up++; } else if (islower(s[i])) { low++; } else if (isdigit(s[i])) { num++; } else { ch++; } } if (up == 0 && low == 0) { sa = 0; } else if (up > 0 && low == 0 || up == 0 && low > 0) { sa = 10; } else if (up > 0 && low > 0) { sa = 20; } if (num == 0) { sn = 0; } else if (num == 1) { sn = 10; } else if (num > 1) { sn = 20; } if (ch == 0) { sc = 0; } else if (ch == 1) { sc = 10; } else if (ch > 1) { sc = 25; } if (up > 0 && low > 0 && num > 0 && ch > 0) { so = 5; } else if ((up > 0 && num > 0 && ch > 0) || (low > 0 && num > 0 && ch > 0)) { so = 3; } else if ((up > 0 && num > 0) || (low > 0 && num > 0)) { so = 2; } score = ss + sa + sn + sc + so; 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; } } return 0; }