华为oj中级 密码验证合格程序

描述
密码要求:

1.长度超过8位

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

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

说明:长度超过2的子串

知识点 字符串,数组
运行时间限制 0M
内存限制 0
输入
一组或多组长度超过2的子符串。每组占一行
输出
如果符合要求输出:OK,否则输出NG

每行输出对应一组输入的结果;

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

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<unordered_map>
#include<fstream>
#include<sstream>
using namespace std;
bool is_qualified(string &s){
    if (s.size() > 8){
        int cnt1 = 0;
        int cnt2 = 0;
        int cnt3 = 0;
        int cnt4 = 0;
        bool flag = false;
        for (int i = 0; i < s.size(); i++){
            if (isdigit(s[i])){
                cnt1=1;
            }
            else if(isalpha(s[i])){
                if (isupper(s[i]))
                    cnt2 = 1;
                else
                    cnt3 = 1;
            }
            else{
                cnt4 = 1;
            }

            if (cnt1 + cnt2 + cnt3 + cnt4 >= 3){
                flag = true;
                break;
            }
        }
        if (flag){
            string str1,str2;
            for (int i = 0; i < s.size() - 5; i++){
                str1 = s.substr(i, 3);
                for (int j = i + 3; j < s.size() - 2; j++){
                    str2 = s.substr(j, 3);
                    if (str1 == str2){
                        return false;
                    }
                }
            }
            return true;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
}
int main(){
    string s;
    while (getline(cin, s)){
        if (is_qualified(s)){
            cout << "OK" << endl;
        }
        else{
            cout << "NG" << endl;
        }
    }
    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值