题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <string> using namespace std; bool checkString(const string& a) { int isnum = 0; int isupper = 0; int islower = 0; int isother = 0; int finder = 0; if (a.length() <= 8) { return false; } for (string::const_iterator it = a.begin(); it != a.end(); it++) { if (isalpha(*it)) { if (abs(*it) >= 97 && abs(*it) <= 123) { islower = 1; } else if (abs(*it) >= 65 && abs(*it) <= 91) { isupper = 1; } } else if (isdigit(*it)) { isnum = 1; } else if (*it != ' ' && *it != '\n') { isother = 1; } } if (isnum + islower + isupper + isother < 3) { return false; } for (int i = 0; i <= a.size() - 3; i++) { string temp = a.substr(i, 3); string temp1 = a.substr(0, i); string temp2 = a.substr(i + 3); string temp3 = temp1 + temp2; finder = temp3.find(temp); if (finder != string::npos) { return false; } } return true; } int main() { string a; while (getline(cin, a)) { if (checkString(a)) { cout << "OK" << endl; } else { cout << "NG" << endl; } } return 0; }