描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
数据范围:
输入的字符串长度满足 1≤n≤100
输入描述:
一组字符串。
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入:
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出:
OK
NG
NG
OK
AC code
/// HJ20 密码验证合格程序
#include <bits/stdc++.h>
using namespace std;
// 2.包括大小写字母.数字.其它符号,以上四种至少三种
bool checkSymbol(string str)
{
bool res;
int upper=0, lower=0, num=0, other=0;
for(int i=0; i<str.size(); i++)
{
if(str[i]>='a'&&str[i]<='z')
lower=1;
else if(str[i]>='A'&&str[i]<='Z')
upper=1;
else if(str[i]>='0'&&str[i]<='9')
num=1;
else if(str[i]!=' '&&str[i]!='\n')
other=1;
}
if(upper+lower+num+other>=3)
res = true;
else
res = false;
return res;
}
// 3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
bool checkSubstr(string str)
{
set<string> sets;
string temp;
for(int i=0; i<str.size()-3; i++)
{
temp = str.substr(i, 3);
if(sets.find(temp) == sets.end())
{
sets.insert(temp);
}
else
{
return false;
}
}
return true;
}
int main()
{
string str;
while(getline(cin, str))
{
int resCnt=0;
// 1.长度超过8位
if(str.size()>8) resCnt++;
if(checkSymbol(str)) resCnt++;
if(checkSubstr(str)) resCnt++;
if(resCnt==3) cout<<"OK"<<endl;
else cout<<"NG"<<endl;
}
return 0;
}