题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <iostream> #include <string> #include <vector> #include <set> using namespace std; bool isOk(string str) { if (str.size() <= 8) return false; int xiaoxie = 0, daxie = 0, shuzi = 0, qita = 0; set<string> _set; for (int i = 0; i < str.size() - 2; i++) { if (str[i] >= '0' && str[i] <= '9') shuzi = 1; else if (str[i] >= 'a' && str[i] <= 'z') xiaoxie = 1; else if (str[i] >= 'A' && str[i] <= 'Z') daxie = 1; else qita = 1; if (_set.find(str.substr(i, 3)) == _set.end()) { _set.insert(str.substr(i, 3)); } else { return false; } } for (int i = str.size() - 2; i < str.size(); i++) { if (str[i] >= '0' && str[i] <= '9') shuzi = 1; else if (str[i] >= 'a' && str[i] <= 'z') xiaoxie = 1; else if (str[i] >= 'A' && str[i] <= 'Z') daxie = 1; else qita = 1; } if ((xiaoxie + daxie + shuzi + qita) < 3) return false; return true; } int main() { vector<string> inp; string temp; while(cin >> temp) { inp.push_back(temp); } for (auto str : inp) { if (isOk(str)) cout << "OK" << endl; else cout << "NG" << endl; } } // 64 位输出请用 printf("%lld")
模拟
#华为OD机试真题#华为OD机测试题 文章被收录于专栏
个人练习专栏