密码验证合格程序

描述

密码要求:

1.长度超过8位

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

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

数据范围:输入的字符串长度满足1≤n≤100 

输入描述:

一组字符串。

输出描述:

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

示例1

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

输出:
OK
NG
NG
OK

代码

#include <iostream>
#include<string.h>
using namespace std;

int main() {
    string str;
    while(cin>>str){
        if(str.length()<=8){
            cout<<"NG"<<endl;
            continue;
        }
            int a[4]={0};
            for(int i=0;i<str.length();i++){
                if(str[i]>='A' && str[i]<='Z')
                    a[0]=1;
                else if(str[i]>='a' && str[i]<='z')
                    a[1]=1;
                else if(str[i]>='0' && str[i]<='9')
                    a[2]=1;
                else
                    a[3]=1;
            }
            int sum=0;
            for(int i=0;i<4;i++)
                sum+=a[i];
            if(sum<3){
                cout<<"NG"<<endl;
                continue;
            } 
        int pos;
        for(int i=0;i<str.length();i++){
            string st=str.substr(i,3);
            pos=str.find(st,i+3);
            if(pos!=str.npos){
               break; 
            }
        }
        if(pos==str.npos){
                cout<<"OK"<<endl;
            }
        else{
                cout<<"NG"<<endl;
            }
    }
}
// 64 位输出请用 printf("%lld")

知识点:string::npos是个特殊值(-1),说明没有匹配

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值