题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
//写的好难看啊
#include <iostream>
#include <vector>
using namespace std;
int main() {
string str;
while (getline(cin, str)) {
int digit = 0, lower = 0, upper = 0, graph = 0;
for (auto i : str) {
if (isdigit(i)) {
digit = 1;
}
if (islower(i)) {
lower = 1;
}
if (isupper(i)) {
upper = 1;
}
if (isgraph(i) && !isalnum(i)) {
graph = 1;
}
}
int labor = 1;
if (str.size() < 9) labor = 0;
for (int i = 0; i < str.size(); i++) {
for (int j = i + 1; j < str.size(); j++) {
if (str[j] == str[i] && str[j + 1] == str[i + 1] && str[j + 2] == str[i + 2]) {
labor = 0;
break;
}
}
}
// cout << labor << endl;
if (digit + lower + upper + graph >= 3 && labor) {
cout << "OK" << endl;
} else {
cout << "NG" << endl;
}
}
}
查看15道真题和解析