题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <cstddef> #include <iostream> #include <set> #include <vector> using namespace std; set<int> kind; set<string> store; int main() { int flag = 0; string s; string tem; while (cin>>s) { // 注意 while 处理多个 case kind.clear(); store.clear(); flag = 0; if(s.size()<8){ cout<<"NG"<<endl; continue; } for(auto x:s){ if(x>='a'&&x<='z'){ kind.insert(0); continue; } if(x>='A'&&x<='Z'){ kind.insert(1); continue; } if(x>='0'&&x<='9'){ kind.insert(2);; continue; } kind.insert(3); } if(kind.size()<3){ cout<<"NG"<<endl; kind.clear(); continue; } for(int i = 0;i<=s.size()-3;i++){ tem = s.substr(i,3); if(store.find(tem)==store.end()){ store.insert(tem); }else{ cout<<"NG"<<endl; flag = 1; break; } } if(flag == 1){ flag = 0; continue; } cout<<"OK"<<endl; } } // 64 位输出请用 printf("%lld")