思路要保持清晰
几个条件分函数写
纯粹考察代码能力
point:substr和find
#include<iostream> #include<string> using namespace std; bool checkchar(string str)//包括大小写字母.数字.其它符号,以上四种至少三种 { int i0 = 0, i1 = 0, i2 = 0, i3 = 0; for (int i = 0; i < str.size(); i++) { if (str[i] >= 'a' && str[i] <= 'z') { i0 = 1; } else if (str[i] >= 'A' && str[i] <= 'Z') { i1 = 1; } else if (str[i] >= '0' && str[i] <= '9') { i2 = 1; } else { i3 = 1; } } if (i0 + i1 + i2 + i3 >= 3) { return true; } else { return false; } } bool checksubstr(string str) { int len = str.size(); for (int i = 0; i < len - 3; i++) { string s = str.substr(i, 3); if (str.find(s, i + 3) != str.npos) //找到重复 { return false; } } return true; } int main() { string str; //循环处理 while (cin >> str) { if (str.size()>8&&checksubstr(str)&&checkchar(str)) { cout << "OK" << endl; } else { cout << "NG" << endl; } } return 0; }