密码验证合格程序

题目描述

密码要求:

1.长度超过8位

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

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

说明:长度超过2的子串

输入描述:

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

输出描述:

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

代码如下,此题唯一的难点是如何有效判断四种符号是否出现3种及3种以上,代码如下,

#include<iostream>
#include<string>
#include<vector>
using namespace std;

void count(char c,vector<int>& ves)
{
    if(c>='a'&&c<='z'){
        ves[0]=1;
    }else if(c>='A'&&c<='Z'){
        ves[1]=1;
    }else if(c>='0'&&c<='9'){
        ves[2]=1;
    }else{
        ves[3]=1;
    }
}
int main()
{
    string str;
    while(getline(cin,str)){
       vector<int> ves(4,0);
       bool isrep=false;
       int i=0,n=str.size();
       for(;i<n-3;i++){
           count(str[i],ves);
           string s=str.substr(i,3);
           if(str.find(s,i+3)!=string::npos){
               isrep=true;
               break;
           }
       } 
        for(;i<n;i++){
             count(str[i],ves);
        }
        int sum=ves[0]+ves[1]+ves[2]+ves[3];
        if(str.size()>8&&sum>=3&&!isrep){
            cout<<"OK"<<endl;
        }else{
            cout<<"NG"<<endl;
        }
    }
    return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值