题解 | #密码强度等级#
密码强度等级
http://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
根据描述写代码就可以,注意细节
#include "stdio.h" #include "string.h" int flag_1_1 = 0, flag_1_2 = 0; int flag_2_1 = 0, flag_2_2 = 0; int flag_3_1 = 0; int flag_4_1 = 0; int main(void) { int i = 0, t = 0, out = 0; char str[301] = {0}; scanf("%s", str); int len = strlen(str); if (len <= 4) { out = 5; } else if (len <= 7) { out = 10; } else { out = 25; } for (i = 0; i < len; i++) { if (str[i] >= 'a' && str[i] <= 'z') { flag_2_1 ++; } else if (str[i] >= 'A' && str[i] <= 'Z') { flag_2_2 ++; } else if (str[i] >= '0' && str[i] <= '9') { flag_3_1 ++; } else if ((str[i] >= 0x21 && str[i] <= 0x2f) || (str[i] >= 0x3a && str[i] <= 0x40) || (str[i] >= 0x5b && str[i] <= 0x60) || (str[i] >= 0x7b && str[i] <= 0x7e) ) { flag_4_1 ++; } } if (flag_2_1 && flag_2_2) { out += 20; } else if (flag_2_1 || flag_2_2) { out += 10; } if (flag_3_1 == 1) { out += 10; } else if (flag_3_1 > 1) { out += 20; } if (flag_4_1 == 1) { out += 10; } else if (flag_4_1 > 1) { out += 25; } if (flag_4_1 && flag_3_1 && flag_2_1 && flag_2_2) { out += 5; } else if (flag_4_1 && flag_3_1 && (flag_2_1 || flag_2_2)) { out += 3; } else if (flag_3_1 && (flag_2_1 || flag_2_2)) { out += 2; } if (out >= 90) { printf("VERY_SECURE"); }else if (out >= 80) { printf("SECURE"); }else if (out >= 70) { printf("VERY_STRONG"); }else if (out >= 60) { printf("STRONG"); }else if (out >= 50) { printf("AVERAGE"); }else if (out >= 25) { printf("WEAK"); }else if (out >= 0) { printf("VERY_WEAK"); } return 0; }