题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include<stdio.h> #include<string.h> int main(void) { char str[101] = { 0 }; while (scanf("%s", &str) != EOF) { char result[10] = { 0 }; int len = strlen(str); int flag1 = 0; int flag2 = 0; int flag3 = 0; int flag4 = 0; int flag5 = 0; int cnt = 0; if (len <= 8) { strcpy(result, "NG"); } else if (len > 8) { for (int i = 0; i < len; i++) { if (str[i] >= '0' && str[i] <= '9') { flag1 = 1; } else if (str[i] >= 'a' && str[i] <= 'z') { flag2 = 1; } else if (str[i] >= 'A' && str[i] <= 'Z') { flag3 = 1; } else { flag4 = 1; } } if ((flag1 + flag2 + flag3 + flag4) >= 3) { //比较公共字串 int num = 3; while (num != len + 1) { for (int i = 0; i <= len - num; i++) { for (int j = i + num; j <= len - num; j++) { for (int k = 0; k < num; k++) { if (str[i + k] == str[j + k]) { flag5++; } } if (flag5 == num) { cnt++; } flag5 = 0; } } num++; } if (cnt > 0) { strcpy(result, "NG"); } else { strcpy(result, "OK"); } } else if ((flag1 + flag2 + flag3 + flag4) < 3) { strcpy(result, "NG"); } } printf("%s\n", result); //printf("%d%d",flag4,cnt); } return 0; }