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

密码验证合格程序

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

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

string fuction(string const& str)
{
    set<int> set;
    
    //至少有8个
    if(str.length()<8)
    {
        return "NG";
    }

    //至少有3种
    for(auto i:str)
    {
        if(i>=48&&i<=57)
        {
            set.insert(1);
        }
        if(i>=65&&i<=90)
        {
            set.insert(2);
        }
        if(i>=97&&i<=122)
        {
            set.insert(3);
        }

        else
            set.insert(4);
    }

    if(set.size()<3)
    {
        return "NG";
    }

    //不能有大于2个字符的子串重复
    for(int i=0;i<str.length()-5;++i)
    {
        for(int j=i+3;j<=str.length()-2;++j)
        {
            if(str[i]==str[j]&&str[i+1]==str[j+1]&&str[i+2]==str[j+2])
            {                   
                return "NG";                      
            }
        }
    }

    return "OK";
}

int main()
{
    int count=0;
    string str;
    while(getline(cin, str))
    {
        cout << fuction(str);
    }
    return 0;
}
全部评论

相关推荐

uu们,拒offer时hr很生气怎么办我哭死
爱睡觉的冰箱哥:人家回收你的offer,或者oc后没给你发offer的时候可不会愧疚你,所以你拒了也没必要愧疚他。
点赞 评论 收藏
分享
自学java狠狠赚一...:骗你点star的,港卵公司,记得把star收回去
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着...:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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