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

描述

密码要求:

1.长度超过8位

2.包括大小写字母.数字.其它符号,以上四种至少三种

3.不能有相同长度大于2的子串重复

输入描述:

一组或多组长度超过2的字符串。每组占一行

输出描述:

如果符合要求输出:OK,否则输出NG

示例
输入:
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出:
OK
NG
NG
OK

代码:

#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;

int main(){
    string str;
    bool A,a,n,c;            // 分别标识大写,小写,数字和字符
    while(getline(cin, str)){
        A = false; a = false; c = false;n = false;
        if(str.size() <= 8){
            cout<<"NG"<<endl;
            continue;
        }
        for(int i = 0; i < str.size(); i++){
            if(str[i] >= 'A' && str[i] <= 'Z'){
                A = true;
            }else if(str[i] >='a' &&str[i] <= 'z'){
                a = true;
            }else if(str[i] >= '0' && str[i] <= '9'){
                n = true;
            }else{
                c = true;
            }
        }
        if((A&&a&&n)||(A&&a&&c)||(A&&c&&n)||(c&&n&&a)){    // 如果有三种组合
            string str2,str3;
            bool b;
            for(int i=0;i<str.size()-5;i++){
                str2 = str.substr(i,3);
                for(int j=i+3;j<str.size()-2;j++){
                    str3 = str.substr(j,3);
                    if(str2.compare(str3)==0){
                        b = false;
                        break;
                    }else b = true;
                }
                if(!b) {cout<<"NG"<<endl;break;}
            }
            if(b) cout<<"OK"<<endl;
        }else{
            cout<<"NG"<<endl;
            continue;
        }
    }
    return 0;
}

写的有点乱,又菜又脑阔疼

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值