密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度超2的子串重复
说明:长度超过2的子串
输入描述:
一组或多组长度超过2的子符串。每组占一行
输出描述:
如果符合要求输出:OK,否则输出NG
输入例子:
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出例子:
OK
NG
NG
OK
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- string str;
- while(cin>>str)
- {
- int flag[4]={0};
- if(str.size()<=8) //长度小于等于8,不合格
- {
- cout<<"NG"<<endl;
- continue;
- }
- for(int i=0; i<str.size(); i++)
- if(str[i] >= 'a' && str[i] <= 'z') flag[0]=1;
- else if(str[i] >= 'A' && str[i] <= 'Z') flag[1]=1;
- else if(str[i] >= '0' && str[i] <= '9') flag[2]=1;
- else flag[3]=1;
- .
- if(flag[0] + flag[1] + flag[2] + flag[3] <3) //使用3种以下,不合格
- {
- cout<<"NG"<<endl;
- continue;
- }
- .
- for(int i=0; i<=str.size()-6; i++)
- for(int j=i+3; j<str.size(); j++)
- {
- if(str[i]==str[j] && str[i+1]==str[j+1] && str[i+2]==str[j+2]) //相同长度超过2,不合格
- cout<<"NG"<<endl;
- continue;
- }
- cout<<"OK"<<endl;
- }
- return 0;
- }
【注】 此程序仅能通过90%样例,正在修改中....