题解 | 密码验证合格程序
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <string> using namespace std; int main() { string input; while(cin >> input){ bool is_ng = false; if(input.size() < 8){ cout << "NG" << endl; is_ng = true; continue; } uint8_t big = 0; uint8_t small = 0; uint8_t num = 0; uint8_t special = 0; uint8_t count = 0; for(char& c : input){ if((c >= 33 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126)){ if(special == 0){ special = 1; count++; } }else if((c >= 48 && c <= 57)){ if(num == 0){ num = 1; count++; } }else if((c >= 65 && c <= 90)){ if(big == 0){ big = 1; count++; } }else if((c >= 97 && c <= 122)){ if(small == 0){ small = 1; count++; } } } if(count < 3){ is_ng = true; cout << "NG" << endl; continue; } string substr1; string substr2; for(size_t begin = 0; begin < input.size(); begin++){ for(size_t length = 3; length < input.size(); length++){ if(input.size() - (begin + length) <= 2){ break; } if(begin + length >= input.size()){ break; } substr1 = input.substr(begin, length); size_t substr_begin = begin + length; while(substr_begin + length < input.size()){ substr2 = input.substr(substr_begin, length); if(substr1 == substr2){ is_ng = true; cout << "NG" << endl; break; } substr_begin++; } //cout << substr1 << endl; //cout << substr2 << endl; } } if(!is_ng){ cout << "OK" << endl; } //cout << "OK" << endl; } return 0; } // 64 位输出请用 printf("%lld")