【华为机试】密码验证合格程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/soeben/article/details/79622233

题目描述:

密码要求:
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;
}

猜你喜欢

转载自blog.csdn.net/soeben/article/details/79622233