题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream>
#include <set>
using namespace std;
int main() {
string str;
while(getline(cin,str))
{
//判断是否长度超过8
if(str.size()<=8)
{
cout<<"NG"<<endl;
continue;
}
//是否有超过3种东西
int count[4]={0,0,0,0};
for(int i =0 ; i<str.size();i++)
{
if(str[i]>='a'&&str[i]<='z')
count[0]=1;
else if(str[i]>='A'&&str[i]<='Z')
count[1]=1;
else if(str[i]>='0'&&str[i]<='9')
count[2]=1;
else
count[3]=1;
}
if((count[0]+count[1]+count[2]+count[3])<3)
{
cout<<"NG"<<endl;
continue;
}
//字符串中不能有长度大于二的字串
multiset<string> s1;
int flag =0;
for(int i =0;i<str.size()-2;i++)
{
string s = str.substr(i,3);
if(s1.find(s)!=s1.end())
{
//找到
cout<<"NG"<<endl;
flag=1;
break;
}
s1.insert(s);
}
if(flag ==0)
{
cout<<"OK"<<endl;
}
}
}
// 64 位输出请用 printf("%lld")

凡岛公司福利 503人发布