【华为 OJ】密码验证合格程序

本文介绍了一种用于验证密码强度的算法实现,确保密码长度超过8位,并包含大小写字母、数字和其他符号中的至少三类字符,同时避免了长度超过2的重复子串,通过具体的输入输出示例展示了算法的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

密码要求:

 

 

 

1.长度超过8位

 

 

 

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

 

 

 

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

 

 

 

说明:长度超过2的子串



输入描述:

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



输出描述:

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


输入例子:
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出例子:
OK
NG
NG

OK

#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str;
    while(cin>>str)
    {//getline(cin,str);
    int c1 = 0, ca = 0, cA = 0, co = 0, temp;
    int len = str.length();
    if (len <= 8)
        cout << "NG"<<endl;
    else
    {
        string sub1, sub2;
        bool flag = false;
        for (int i = 0; i < len - 2; i++)
        {
            sub1 = str.substr(i, 3);
            for (int j = i + 1; (j < len - 3) && (flag == false); j++)
            {
                sub2 = str.substr(j, 3);
                if (sub1 == sub2)
                    flag = true;
            }
        }
        if (flag == true)
            cout << "NG"<<endl;
        else
        {
            for (int i = 0; i < len; i++)
            {
                if (isdigit(str[i]))
                    c1 = 1;
                else if (islower(str[i]))
                    ca = 1;
                else if (isupper(str[i]))
                    cA = 1;
                else
                    co = 1;
            }
            temp = c1 + ca + cA + co;
            if (temp >= 3)
                cout << "OK"<<endl;
            else
                cout << "NG"<<endl;
        }
    }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值