题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
bool isCorrect(string str) {
if (str.size() <= 8) {
return false;
}
int capital = 0;
int small = 0;
int num = 0;
int other = 0;
for (int i = 0; i < str.size(); i++) {
int temp = (int)str[i];
if (temp >= 65 && temp <= 90) {
capital = 1;
} else if (temp >= 97 && temp <= 122) {
small = 1;
} else if (temp >= 48 && temp <= 57) {
num = 1;
} else {
other = 1;
}
}
if (capital+small+num+other < 3) {
return false;
}
for (int i=0; i<str.size()-5; i++) {
string tmp1 = str.substr(i,3);
for(int j=i+3; j<str.size()-2; j++){
string tmp2 = str.substr(j,3);
if(tmp1==tmp2){
return false;
}
}
}
return true;
}
int main() {
string input;
while (getline(cin, input)) {
istringstream s(input);
string str;
getline(s, str, ' ');
if(isCorrect(str)){
cout<<"OK"<<endl;
}else {
cout<<"NG"<<endl;
}
}
}
// 64 位输出请用 printf("%lld")


OPPO公司福利 1059人发布