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

密码验证合格程序

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

#include <iostream>
#include <set>
using namespace std;

int main() {
    string str;
    while(getline(cin,str))
    {
        //判断是否长度超过8
        if(str.size()<=8)
        {
            cout<<"NG"<<endl;
            continue;
        }
        //是否有超过3种东西
        int count[4]={0,0,0,0};
        for(int i =0 ; i<str.size();i++)
        {
            if(str[i]>='a'&&str[i]<='z')
                count[0]=1;
            else if(str[i]>='A'&&str[i]<='Z')
                count[1]=1;
            else if(str[i]>='0'&&str[i]<='9')
                count[2]=1;
            else
                count[3]=1;
        }
        if((count[0]+count[1]+count[2]+count[3])<3)
        {
            cout<<"NG"<<endl;
            continue;
        }
        //字符串中不能有长度大于二的字串
        multiset<string> s1;
        int flag =0;
        for(int i =0;i<str.size()-2;i++)
        {
            string s = str.substr(i,3);
            if(s1.find(s)!=s1.end())
            {
                //找到
                cout<<"NG"<<endl;
                flag=1;
                break;
            }
            s1.insert(s);
        }
        if(flag ==0)
        {
        cout<<"OK"<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

迟缓的马里奥求你们别...:我双2,FPGA方向,在成都找工作投了上百家,收到面试的不超过10家,是成都这个地方太有说法了。西南柬埔寨
秋招,不懂就问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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