题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str;
    while(cin>>str)
    {
        int a[4]={0},fz=0,cf=0;
        if(str.size()>8)
        {
            for(int i=0;i<str.size();i++)
            {
                if(str[i]>='a'&&str[i]<='z')
                {
                    a[0]=1;
                }else if (str[i]>='0'&&str[i]<='9') {
                    a[1]=1;
                }else if (str[i]>='A'&&str[i]<='Z') {
                    a[2]=1;
                }else {
                    a[3]=1;
                }
            }
            if(a[0]+a[1]+a[2]+a[3]>=3)
            {
                fz=1;
            }
            else {
            //cout<<"fz";
            }
            for(int j=3;j<=str.size()/2;j++)//子串
            {
                for(int k=0;k<str.size()-j;k++)
                {
                    string s1=str.substr(k,j),s2=str.substr(k+j);
                    if(s2.find(s1)>0 && s2.find(s1)<str.size())
                    {
                        cf=1;
                        //cout<<s1<<" cf";
                        break;
                    }
                }
                if(cf==1)
                {
                    break;
                }
            }
            if(fz==1&&cf==0)
            {
                cout<<"OK"<<endl;
            }
            else {
                cout<<"NG"<<endl;
            }
        }else {
                //cout<<"cd"<<endl;
                cout<<"NG"<<endl;
            }
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务