题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <vector> using namespace std; string IsRight(string s){ //1.长度超过8位 if (s.length() < 8) return "NG"; //2.包括大小写字母.数字.其它符号,以上四种至少三种 string str = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789" "~`!@#$%^&*(){}[]|;:',./<>?-=——+"; int f1 = 0, f2 = 0, f3 = 0,f4 = 0; for (int i = 0; i < s.length(); i++){ if (f1+f2+f3+f4 >= 3) break; int pos = str.find(s[i]); if (pos >= 0 && pos <= 25){ f1 = 1; } else if (pos > 25 && pos <= 51){ f2 = 1; } else if (pos > 51 && pos <= 61){ f3 = 1; } else if (pos > 61 && pos < str.length()){ f4 = 1; } } if (f1+f2+f3+f4 < 3) return "NG"; // 3.不能有长度大于2的包含公共元素的子串重复 int m = 0; bool flag = false; while (m < s.length()-3){ string tmp1 = s.substr(m, 3); string tmp2 = s.substr(m+3, s.length()-m-2); int pos = tmp2.find(tmp1); if (pos >= 0){ flag = true; break; } m += 1; } if (flag) return "NG"; return "OK"; } int main() { string s; while (cin >> s){ cout << IsRight(s) << endl; } } // 64 位输出请用 printf("%lld")