【华为OJ】【017-密码验证合格程序】
题目链接:
https://blog.csdn.net/DERRANTCM/article/details/51328467
C++实现:
void main()
{
string str1,strOut;
vector<string> strList,strValid;
// cin >> str1;
str1 = "021Abc9000;021Abc9Abc1;021ABC9000;021$bc9000;";
//分割字符串
string::size_type pos1 = 0,pos2;
pos2 = str1.find(";");
while(pos2 != str1.npos)
{
strList.push_back(str1.substr(pos1,pos2-pos1));
pos1 = pos2 + 1;
pos2 = str1.find(";",pos1);
}
regex r1("^(.*|.+)([0-9]+)(.*|.+)$"),
r2("^(.*|.+)([a-z]+)(.*|.+)$"),
r3("^(.*|.+)([A-Z]+)(.*|.+)$"),
r4("^(.*|.+)([^0-9a-zA-Z]+)(.*|.+)$");
char dir;
int x1=0,y1=0,n1,n2;
stringstream ss;
for (int i=0;i<strList.size();i++)
{
if (strList[i].size() <= 8)
{
cout << "NG" << endl;
continue;
}
n1 = 0;
n1 += regex_match(strList[i],r1)?1:0;
n1 += regex_match(strList[i],r2)?1:0;
n1 += regex_match(strList[i],r3)?1:0;
n1 += regex_match(strList[i],r4)?1:0;
if (n1 < 3)
{
cout << "NG" << endl;
continue;
}
string strSub1,strSub2;
bool success = true;
for (int j=0;j<strList[i].size() -5;j++)
{
strSub1 = strList[i].substr(j,3);
strSub2 = strList[i].substr(j+3);
if (strSub2.find(strSub1) != strSub2.npos)
{
success = false;
break;;
}
}
if (!success)
{
cout << "NG" << endl;
continue;
}
cout << "OK" << endl;
}
system("pause");
}