关键函数:string s s.substr(2,3)
s.find("ab",2),如果没找到,返回-1
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
int dx = 0, xx = 0, sz = 0, qt = 0, zl = 0, cont = 0, find, time = 0;
while (cin >> s){
if (s.size() > 8){ //首先判断字符串长度
for (int i = 0; i < s.size(); i++){
if (s[i] >= '0'&&s[i] <= '9'){
sz = 1;
}
if (s[i] >= 'A'&&s[i] <= 'Z'){
dx = 1;
}
if (s[i] >= 'a'&&s[i] <= 'z'){
xx = 1;
}
if (s[i]<'0' || (s[i]>'9'&&s[i]<'A') || (s[i]>'Z'&&s[i]<'a') || (s[i]>'z')){
qt = 1;
}
}
zl = sz + dx + xx + qt;
if (zl >= 3){
for (int k = 0; k < s.size() - 3; k++){
string zc = s.substr(k, 3);
find = s.find(zc, k + 3);
if (find != -1){
cont++;
}
}
if (cont == 0){
cout << "OK" << endl;
}
else{
cout << "NG" << endl;
cont = 0;
}
}
}
if (s.size() <= 8){
cout << "NG" << endl;
}
if (zl < 3){
cout << "NG" << endl;
}
}
return 0;
}