题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <bits/stdc++.h>
using namespace std;
bool Password_Type(string password){
int big=0,small=0,num=0,other=0;
for (auto x:password) {
if(isdigit(x)) num=1;
else if (isupper(x)) big=1;
else if (islower(x)) small=1;
else if (x!=' '||x!='\n') other=1;
}
if (big+small+num+other>=3) {return true;}
else return false;
}
bool Same_SubString(string password){
map<string,int> m;
string A;
for(int i=0;i<=password.length()-3;++i){
A=password.substr(i,3);
m[A]+=1;
}
for(auto x:m){
if(x.second==2) return false;
}
return true;
}
int main() {
string key;
while (cin>>key) {
if(key.length()<=8||!Password_Type(key)||!Same_SubString(key))
cout<<"NG"<<endl;
else{cout<<"OK"<<endl;}
}
return 0;
}

