HJ20 密码验证合格程序

输入描述:
一组或多组长度超过2的字符串。每组占一行

输出描述:
如果符合要求输出:OK,否则输出NG
在这里插入图片描述
上代码:

#include<iostream>
using namespace std;

string judge(string str)
{
    if(str.length() <= 8)
        return "NG";
    
    int count1= 0 , count2 = 0, count3 = 0 , count4 = 0;
    for(int i = 0 ; i < str.length() ; i++)
    {
        if(str[i] >= 'a' && str[i] <= 'z')
            count1 = 1 ;
        else if(str[i] >= 'A' && str[i] <= 'Z')
            count2 = 1;
        else if(str[i] >= '0' && str[i] <= '9')
            count3 = 1;
        else
            count4 = 1;
    }
    int sum = count1+count2+count3+count4;
    if(sum < 3)
        return "NG";
    
    int flag = 0;
    for(int i = 0 ; i < str.size()-3 ; i++)
    {
        if(flag)
            break;
        for(int j = i+1 ; j < str.size()-2 ; j++)
        {
            string temp1 = str.substr(i,3);
            string temp2 = str.substr(j,3);
            if(temp1.compare(temp2) == 0)
            {
                flag = 1;
                break;
            }
            
        }
    }
    if(flag)
        return "NG";
    else
        return "OK";
}
int main()
{
    string str;
    while(cin >> str)
    {
        cout<< judge(str) << endl;
    }
    return 0;
}

思路分析:
这道题我是将判断完全写成了一个函数里;但是可以不可以多个函数嘞,抽时间写一下;写成两个函数去判断,通过最终判断返回值是否正常,来看返回是NG还是OK

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值