题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <bits/stdc++.h> using namespace std; int main() { string str; getline(cin, str); int score=0; if(str.size()<=4){ score += 5; } else if(str.size()<=7){ score += 10; } else score += 25; int count_lower = 0, count_upper = 0, count_digit = 0, count_symbol = 0; for(int i=0; i<str.size(); i++){ if(islower(str[i])){ count_lower ++; } else if(isupper(str[i])){ count_upper ++; } else if(isdigit(str[i])){ count_digit ++; } else count_symbol ++; } if(count_lower == 0 && count_upper == 0) score += 0; else if((count_lower != 0 && count_upper == 0) || (count_lower == 0 && count_upper != 0)) score += 10; else score += 20; if(count_digit == 0) score += 0; else if(count_digit == 1) score += 10; else score += 20; if(count_symbol == 0) score += 0; else if(count_symbol == 1) score += 10; else score += 25; if(count_lower != 0&& count_upper != 0 && count_digit != 0 && count_symbol != 0) score += 5; else if(((count_lower != 0&& count_upper == 0) || (count_lower == 0&& count_upper != 0)) && count_digit != 0 && count_symbol != 0) score += 3; else if(((count_lower != 0&& count_upper == 0) || (count_lower == 0&& count_upper != 0)) && count_digit != 0 && count_symbol == 0) score += 2; 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 cout << "VERY_WEAK" << endl; } // 64 位输出请用 printf("%lld")