题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> using namespace std; bool judge1(string str){ int cnt[4] = {0}; for(int i = 0; i < str.length(); i ++){ if(str[i] >= 65 && str[i] <= 90 && cnt[0] == 0) cnt[0]++; if(str[i] >= 97 && str[i] <= 122 && cnt[1] == 0) cnt[1]++; if(str[i] >= 48 && str[i] <= 58 && cnt[2] == 0) cnt[2]++; if((str[i] <= 47 || str[i] >= 59 && str[i] <= 64 || str[i] >= 91 && str[i] <= 96 || str[i] >= 123) && cnt[3] == 0 ) cnt[3]++; } int a = 0; for(int i = 0; i <4; i++){ a += cnt[i]; } if(a >= 3) return true; else return false; } bool judge2(string str){ for(int i = 0, j = 0; i < str.length(); i ++){ for(int j = i + 1; j < str.length() - 2; j ++){ if(str[i] == str[j] && str[i+1] == str[j+1] && str[i+2] == str[j+2]) return false; } } return true; } int main() { string str; while(cin >> str){ if(judge1(str) && judge2(str) && str.length()>8) cout << "OK" << endl; else cout << "NG" << endl; } return 0; } // 64 位输出请用 printf("%lld")