题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <set> using namespace std; int main() { string str; while (getline(cin, str)) { int a[4] = {0}; for (auto i : str) { if (i >= 'A' && i <= 'Z') { a[0] = 1; } else if (i >= 'a' && i <= 'z') { a[1] = 1; } else if (i >= '0' && i <= '9') { a[2] = 1; } else a[3] = 1; } int sum = a[0] + a[1] + a[2] + a[3]; bool zc1 = true; for (auto i : str) { if (i == ' ' || i == '\n') { zc1 = false; break; } } bool zc2 = true; set<string>st; string s; for (int i = 0; i < str.length() - 2; i++) { s = str.substr(i, 3); if (st.find(s) == st.end()) { st.insert(s); } else { zc2 = false; break; } } if (str.length() > 8 && sum >= 3 && zc1 && zc2) cout << "OK" << endl; else cout << "NG" << endl; } } // 64 位输出请用 printf("%lld")