题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream>
using namespace std;
int main() {
string str;
while(cin>>str){
if(str.size()<=8){
cout<<"NG"<<endl;
continue; //跳过本次输入循环
}
int upper=0,lower=0,num=0,symble=0;
for(int i=0;i<str.size();i++){
if(isupper(str[i])){
upper=1;
}else if(islower(str[i])){
lower=1;
}else if(isdigit(str[i])){
num=1;
}else{
symble=1;
}
}
if((upper+lower+num+symble)<3){
cout<<"NG"<<endl;
continue;
}
bool flag=false;
for(int i=0;i<str.size()-6;i++){
for(int j=i+3;j<str.size();j++){
if(str.substr(i,3)==str.substr(j,3)){
flag=true; //有相等子串
break;
}
}
}
if(flag){
cout<<"NG"<<endl;
}else{
cout<<"OK"<<endl;
}
}
return 0;
}
// 64 位输出请用 printf("%lld")

查看20道真题和解析