HJ 20 密码验证合格程序

思路:

先统计大小写,数字,其他出现的情况,接着判断长度,最后判断是否有重复子串。

子串的统计,复杂度为O(N2);

题目描述

密码要求:

1.长度超过8位

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

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

输入描述:

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

输出描述:

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

示例1

输入

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出

OK
NG
NG
OK

Example:

#include<iostream>
using namespace std;
enum {UPPER, LOWER, NUMBER, OTHERS};
int main()
{
    char password[256];
    int type[4];
    while(cin.getline(password, 256)) {
        bool OK = true;
        for(int i = 0; i < 4; i++) type[i] = 0;
        int len = 0;
        char ch = password[len];
        while(ch != '\0') {
            if(isdigit(ch)) {
                type[NUMBER] = 1;
            } else if(isupper(ch)) {
                type[UPPER] = 1;
            } else if(islower(ch)) {
                type[LOWER] = 1;
            } else {
                type[OTHERS] = 1;
            }
            ch = password[++len];
        }
        if(len <= 8) OK = false;
        else {
            int count = 0;
            for(int i = 0; i < 4; i++) {
                count += type[i];
            }
            if(count < 3) OK = false;
            else {
                int match = 0;
                for(int i = 0; i < len; i++) {
                    for(int j = i + 1; j < len; j++) {
                        int tmp = i;
                        match = 0;
                        while(j < len && password[tmp] == password[j]) {
                            tmp++, j++, match++;
                        }
                        if(match > 2) {
                            OK = false;
                            break;
                        }
                    }
                    if(!OK) break;
                }
            }
        }
        cout << (OK ? "OK\n" : "NG\n");
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值