题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <string> using namespace std; int main() { int a = 0, b = 0, c = 0, d = 0; string inp; cin >> inp; if (inp.length() <= 8) { cout << "NG" << endl; return 0; } for (char c : inp) { if (c <= 'Z' && c >= 'A') a++; else if (c <= 'z' && c >= 'a') b++; else if (c <= '9' && c >= '0') c++; else d++; } if (a+b+c+d < 3) { cout << "NG" << endl; return 0; } for (int i=0;i<inp.length()-3;i++) { string subs = inp.substr(i, 3); if (inp.find(subs.c_str(), i+3) != string::npos) { cout << "NG" << endl; return 0; } } cout << "OK" << endl; return 0; } // 64 位输出请用 printf("%lld")