题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
#include <stdio.h> #include <string.h> int main() { char str[350]; int bool[130] = {0}; gets(str); int len = strlen(str); for (int i = 0; i < len; i++) { int k = str[i]; bool[k]++; } int c21 = 0, c22 = 0, c3 = 0, c4 = 0; for (int i = 33; i < 127; i++) { if (bool[i] != 0) { if (i >= 48 && i <= 57) { c3++; }//数字 else { if (i >= 65 && i <= 90) { c21++; }//小写字母 else { if (i >= 97 && i <= 122) { c22++; }//大写字母 else c4++;//符号 } } } } //printf("%d %d\n",c21,c22); int sum = 0; if (len < 5) sum += 5; else { if (len > 7) sum += 25; else sum += 10; } if (c21 != 0 && c22 != 0) sum += 20; else { if (c21 == 0 && c22 == 0) sum += 0; else sum += 10; } if (c3 > 1) sum += 20; else if (c3 == 1) sum += 10; else sum += 0; if (c4 > 1) sum += 25; else if (c4 == 1) sum += 10; else sum += 0; //printf("%d\n",sum); while (1) { if (c21 != 0 && c22 != 0 && c3 != 0 && c4 != 0) { sum += 5; break; } if ((c21 != 0 && c22 == 0 && c3 != 0 && c4 != 0) || (c21 == 0 && c22 != 0 && c3 != 0 && c4 != 0)) { sum += 3; break; } if ((c21 != 0 && c22 == 0 && c3 != 0) || (c21 == 0 && c22 != 0 && c3 != 0)) { sum += 2; break; } break; } //printf("%d\n",sum); if (sum >= 90) printf("VERY_SECURE\n"); else if (sum < 90 && sum >= 80) printf("SECURE\n"); else if (sum < 80 && sum >= 70) printf("VERY_STRONG\n"); else if (sum < 70 && sum >= 60) printf("STRONG\n"); else if (sum < 60 && sum >= 50) printf("AVERAGE\n"); else if (sum < 50 && sum >= 25) printf("WEAK\n"); else printf("VERY_WEAK\n"); return 0; }