欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

密码验证合格程序

程序员文章站 2022-07-13 14:20:42
...

题目链接

#include <iostream>
#include <cstring>
using namespace std;

bool isThree(string s) {
    int ans[4] = {0, 0, 0, 0};
    for(int i = 0; i < s.length(); i++) {
        if(s[i] >= 'a' && s[i] <= 'z') {
            ans[0] = 1;
        } else if(s[i] >= 'A' && s[i] <= 'Z') {
            ans[1] = 1;
        } else if(s[i] >= '0' && s[i] <= '9') {
            ans[2] = 1;
        } else {
            ans[3] = 1;
        }
    }
    int n = ans[0] + ans[1] + ans[2] + ans[3];
    if(n >= 3) return true;
    return false;
}

//是否没有重复子串
//没有返回 true
//有返回 false
bool isNotRepeat(string str) {
    bool flag = true;
    for(int i = 0; i <= str.size() - 6; i++)
        for(int j = i + 3; j < str.size(); j++)
            if(str[i] == str[j] && str[i + 1] == str[j + 1] && str[i + 2] == str[j + 2]) {
				flag = false;
				break;
            } 
/*     
    for(int i = 0; i < s.length() - 4; i++) {
	    char buf[4] = {'0', '0', '0', '\0'};
	    buf[0] = s[i];
		buf[1] = s[i + 1];
		buf[2] = s[i + 2];
		string tmp = buf;
		cout << "当前检测的子串: " << tmp << endl;		
		if(s.find(tmp, i + 3) != s.npos) {
		    cout << "发现重复子串: " << tmp << endl;
			//cout << "其第一个出现的位置: " << s.find_first_of(tmp) << endl;
		    //cout <<	"其最后一个出现的位置: " << s.find_last_of(tmp) << endl;
			flag = false;
			break;
		}
    }
*/
    return flag;
}

int main() {
    string s;
    while(getline(cin, s)) {
        
        if(s.length() <= 8) {
            cout << "NG" << endl;
            continue;
        }
 
        bool thr = isThree(s);

        bool rep = isNotRepeat(s);	
      
        if(thr == true && rep == true) 
            cout << "OK" << endl;
        else 
            cout << "NG" << endl;
    }
    return 0;
}