HJ20 密码验证合格程序

描述

密码要求:

1.长度超过8位

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

3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)

数据范围:

输入的字符串长度满足 1≤n≤100 

输入描述:

一组字符串。

输出描述:

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

示例1

输入:

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出:

OK
NG
NG
OK

AC code

/// HJ20 密码验证合格程序
#include <bits/stdc++.h>
using namespace std;

// 2.包括大小写字母.数字.其它符号,以上四种至少三种
bool checkSymbol(string str)
{
    bool res;
    int upper=0, lower=0, num=0, other=0;
    for(int i=0; i<str.size(); i++)
    {
        if(str[i]>='a'&&str[i]<='z')
            lower=1;
        else if(str[i]>='A'&&str[i]<='Z')
            upper=1;
        else if(str[i]>='0'&&str[i]<='9')
            num=1;
        else if(str[i]!=' '&&str[i]!='\n')
            other=1;
    }

    if(upper+lower+num+other>=3)
        res = true;
    else
        res = false;

    return res;
}

// 3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
bool checkSubstr(string str)
{
    set<string> sets;
    string temp;
    for(int i=0; i<str.size()-3; i++)
    {
        temp = str.substr(i, 3);
        if(sets.find(temp) == sets.end())
        {
            sets.insert(temp);
        }
        else
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string str;
    while(getline(cin, str))
    {
        int resCnt=0;

        // 1.长度超过8位
        if(str.size()>8) resCnt++;
        if(checkSymbol(str)) resCnt++;
        if(checkSubstr(str)) resCnt++;

        if(resCnt==3) 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、付费专栏及课程。

余额充值