【華爲機試】密碼驗證合格程序

題目描述:

密碼要求:
1.長度超過8位
2.包括大小寫字母.數字.其它符號,以上四種至少三種
3.不能有相同長度超2的子串重複


輸入描述:

一組或多組長度超過2的子符串。每組佔一行


輸出描述:

如果符合要求輸出:OK,否則輸出NG

示例1
輸入
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
輸出
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

參考程序:

#include <iostream>
#include <string>
using namespace std;
int main(){
    int a=0,b1=0,b2=0,b3=0,b4=0;
    char s;
    string str="";
    while(cin.get(s)){
        if(s=='\n'||s==' '){
            if(a>8&&((b1+b2+b3+b4)>=3)){
                for(int i = 0; i <= a-6; i++)
                    for(int j = i+3;j < a;j++)
                        if(str[i] == str[j] && str[i+1] == str[j+1] &&str[i+2] == str[j+2])
                            goto NG;
                goto OK;
            }
            NG: 
                cout<<"NG"<<endl;
                goto RE;
            OK:
                cout<<"OK"<<endl;
            RE:
                a=0;b1=0;b2=0;b3=0;b4=0;str="";
        }
        else{
            ++a;
            if(s>='a' && s<='z') b1=1;
            else if(s>='A' && s<='Z') b2=1;
            else if(s>='0' && s<='9') b3=1;
            else b4=1;
            str = str+s;
        }
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章