数据范围:输入的字符串长度满足 1≤n≤100 1≤n≤100
输入描述:
一组字符串。
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入:
021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000
输出:
OK NG NG OK
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int a=0;//表示可以是OK的
//长度
if(str.size()<=8)
{
a=1;
}
//字符
int n1=0,n2=0,n3=0,n4=0;//各类别的种类
for(int i=0;i<str.size();i++)
{
if(str[i]>='0'&&str[i]<='9')//数字可以
{
n1=1;
//cout<<n1;
}
else if(str[i]>='a'&&str[i]<='z')//小写可以
{
n2=1;
//cout<<n2;
}
else if(str[i]>='A'&&str[i]<='Z')//大写可以
{
n3=1;
//cout<<n3;
}
else//奇怪字符可以
{
n4=1;
//cout<<n4;
}
}
if((n1+n2+n3+n4)<3)
{
a=1;
}
//重复字符串(只要发现3个就行,就按照3来算
for(int i=0;i<str.size()-3;i++)
{
for(int j=i+1;j<str.size()-3;j++)
{
if(str[i]==str[j]&&str[i+1]==str[j+1]&&str[i+2]==str[j+2])
{
a=1;
// cout<<i;
// cout<<j;
}
}
}
// cout<<a<<endl;
// cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<endl;
if(a==1)
{
cout<<"NG"<<endl;
}
if(a==0)
{
cout<<"OK"<<endl;
}
}
}
小课堂:
为了验证结果还是画费了一些功夫的,结果发现自己的j写成了i,有点苦笑不得
然后字符比较的时候可能会经常性的忘记单引号