题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <cctype> #include <iostream> #include <string> using namespace std; int main() { string strInput; while (getline(cin, strInput)) { // 注意 while 处理多个 case int score = 0; size_t leng = strInput.length(); if (leng <= 4) { score += 5; } else if (leng <= 7) { score += 10; } else { score += 25; } int numCount = 0, lowerCount = 0, supperCount = 0, specialCount = 0; for (int i = 0; i < leng; i++) { if (isdigit(strInput.at(i))) { numCount++; } else if (islower(strInput.at(i))) { lowerCount++; } else if (isupper(strInput.at(i))) { supperCount++; } else if (ispunct(strInput.at(i))) { specialCount++; } } if (lowerCount != 0 && supperCount != 0) { score += 20; } else if (lowerCount != 0 || supperCount != 0) { score += 10; } if (numCount > 1) { score += 20; } else if (numCount == 1) { score += 10; } if (specialCount > 1) { score += 25; } else if (specialCount == 1) { score += 10; } if (numCount > 0) { if (specialCount > 0) { if (lowerCount > 0 && supperCount > 0) { score += 5; } else if (lowerCount > 0 || supperCount > 0) { score += 3; } } else if (lowerCount > 0 || supperCount > 0) { score += 2; } } if (score >= 90) { cout << "VERY_SECURE"; } else if (score >= 80) { cout << "SECURE"; } else if (score >= 70) { cout << "VERY_STRONG"; } else if (score >= 60) { cout << "STRONG"; } else if (score >= 50) { cout << "AVERAGE"; } else if (score >= 25) { cout << "WEAK"; } else { cout << "VERY_WEAK"; } } return 0; } // 64 位输出请用 printf("%lld")