题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <string> #include <map> #include <vector> using namespace std; string check(string str); int main() { string psw; while(cin>>psw){ cout<<check(psw)<<endl; } return 0; } string check(string psw){ string str,result="OK"; map<int,int> hash; if(psw.size()<=8){result="NG";} else { for(int i=0;i<psw.size();i++){ if(psw[i]>='A'&&psw[i]<='Z')hash[0]=1; else if(psw[i]>='a'&&psw[i]<='z')hash[1]=1; else if(psw[i]>='0'&&psw[i]<='9')hash[2]=1; else hash[3]=1; str=psw.substr(i,3); //for(int j=0;j<psw.size()-3;j++) if(psw.rfind(str)>i){ result="NG"; } } } if(hash.size()<3)result="NG"; return result; } // 64 位输出请用 printf("%lld")