题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <stdio.h> #include <string.h> int main() { char str[100]; while ((scanf("%s", str) != EOF)) { int len = strlen(str); int change[4] = {0}; int num = 0; int flag = 0; int yy = 0; //判断密码长度是否符合 if (len < 8) { printf("NG\n"); continue; } //判断密码元素是否齐全; for (int i = 0 ; i < len ; i ++) { if ( str[i] >= '0' && str[i] <= '9') { change[0] = 1; continue; } else if (str[i] >= 'a' && str[i] <= 'z') { change[1] = 1; continue; } else if (str[i] >= 'A' && str[i] <= 'Z') { change[2] = 1; continue; } else { change[3] = 1; continue; } } for (int i = 0 ; i < 4 ; i++) { if (change[i] == 1) { num++; } } if (num < 3) { printf("NG\n"); continue; }; //判断密码是否有长度大于二的包含公共元素的字串重复 for (int i = 0 ; i < len - 6 ; i++) { for (int j = i + 3 ; j < len - 3 ; j++) { if (str[i] == str[j] && str[i + 1] == str[j + 1] && str[i + 2] == str[j + 2]) { yy = 1; break; } } if (yy) { break; } } if (yy) { printf("NG\n"); continue; } printf("OK\n"); continue; } return 0; }#罗里吧嗦#