题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream>
#include <string>
#include<cstring>
using namespace std;
int fun(string str);
int main()
{
string str;
int a = 0;
while (getline(cin,str))
{
if (str.size() <= 8)
//cout<<"重新输入"<<endl;
{
cout << "NG" << endl;
goto here;
}
for (int i = 0; i < str.size(); i++)
{
if (str[i] == '\0' || str[i] == '\n')
{
cout << "NG" << endl;
goto here;
}
}
//出现两次
for (int i = 0; i < str.size()-2; ++i)
{
string str1 = str.substr(i, 3);
int cc = 0;
for (int j = 0; j < str.size()-2; ++j)
{
string str2 = str.substr(j, 3);
if (str1 == str2)
{
cc++;
if (cc >= 2)
{
cout << "NG" << endl;
goto here; //可以加goto,,,也可以在循环加多个break,比如if()break;
}
}
}
}
a = fun(str);
if (a >= 3)
cout << "OK" << endl;
else
cout << "NG" << endl;
here:
cin.get();
}
//here:
return 0;
}
int fun(string str)
{
int num = 0, low_word = 0, up_word = 0, other = 0;
int flag = 0;
for (int i = 0; i < int(str.size()); i++)
{
if (str[i] >= '0' && str[i] <= '9')
num++;
else if (str[i] >= 'a' && str[i] <= 'z')
low_word++;
else if (str[i] >= 'A' && str[i] <= 'Z')
up_word++;
else
other++;
}
if (num > 0)
flag++;
if (low_word > 0)
flag++;
if (up_word > 0)
flag++;
if (other > 0)
flag++;
return flag;
}
#include <string>
#include<cstring>
using namespace std;
int fun(string str);
int main()
{
string str;
int a = 0;
while (getline(cin,str))
{
if (str.size() <= 8)
//cout<<"重新输入"<<endl;
{
cout << "NG" << endl;
goto here;
}
for (int i = 0; i < str.size(); i++)
{
if (str[i] == '\0' || str[i] == '\n')
{
cout << "NG" << endl;
goto here;
}
}
//出现两次
for (int i = 0; i < str.size()-2; ++i)
{
string str1 = str.substr(i, 3);
int cc = 0;
for (int j = 0; j < str.size()-2; ++j)
{
string str2 = str.substr(j, 3);
if (str1 == str2)
{
cc++;
if (cc >= 2)
{
cout << "NG" << endl;
goto here; //可以加goto,,,也可以在循环加多个break,比如if()break;
}
}
}
}
a = fun(str);
if (a >= 3)
cout << "OK" << endl;
else
cout << "NG" << endl;
here:
cin.get();
}
//here:
return 0;
}
int fun(string str)
{
int num = 0, low_word = 0, up_word = 0, other = 0;
int flag = 0;
for (int i = 0; i < int(str.size()); i++)
{
if (str[i] >= '0' && str[i] <= '9')
num++;
else if (str[i] >= 'a' && str[i] <= 'z')
low_word++;
else if (str[i] >= 'A' && str[i] <= 'Z')
up_word++;
else
other++;
}
if (num > 0)
flag++;
if (low_word > 0)
flag++;
if (up_word > 0)
flag++;
if (other > 0)
flag++;
return flag;
}