密码验证合格程序

来源:互联网 发布:debian与centos 编辑:程序博客网 时间:2024/05/21 19:30

题目

描述

密码要求:

1.长度超过8位

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

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

说明:长度超过2的子串

输入

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

输出

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

每行输出对应一组输入的结果;

样例输入

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

样例输出

OK
NG
NG
OK

代码

#include <iostream>#include <string>#include <vector>#include <ctype.h>using namespace std;int LRS(string a){    int len=a.size();    int Max=0,count=0;    int start1,start2;    for(int i=0; i<len; i++)    {        for(int j=i+1; j<len; j++)        {            start1=i;            start2=j;            while(a[start1]==a[start2] && start1<len && start2<len)            {                count++;                start1++;                start2++;            }            if(count>Max)            {                Max=count;            }            count=0;        }    }    return Max;}int BoolStrong(string &str){    int counta=0,countA=0,countS=0,count1=0; //计数    int temp;    int length=str.size();    if(length>8)  //长度大于8    {        for(int i=0; i<length; i++)        {            if(isdigit(str[i]))            {                count1=1;            }            else if(islower(str[i]))            {                counta=1;            }            else if(isupper(str[i]))            {                countA=1;            }            else            {                countS=1;            }        }        temp=counta+countA+countS+count1;        if(temp>=3)      //四种里面至少有3种        {            if (LRS(str)>2)//不能有相同长度超2的子串重复            {                return  0;            }            else            {                return 1;            }        }        else        {            return 0;        }    }    else    {        return 0;    }}int main(){    string str;    vector<string> vec;    while (getline(cin,str))    {        string tmpstr;        if (BoolStrong(str))        {            tmpstr="OK";        }        else        {            tmpstr="NG";        }        vec.push_back(tmpstr);    }    for (vector<string>::iterator iter=vec.begin(); iter!=vec.end(); ++iter)    {        cout<<(*iter)<<endl;    }}

这里写图片描述
ctrl+z终止输入

0 0