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

密码验证合格程序

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

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

int main() {
    string s;
    cin>>s;

    bool valid = true;

    if(s.size()<=8){//若长度不符合要求
        valid = false;
    }else{
        bool haveUpperLetter,haveLowerLetter,haveDigit,haveOther;
        haveUpperLetter = haveLowerLetter = haveDigit = haveOther = false;
        set<string> subset;//存放长度为3的子串
        for(int i=0;i<s.size();i++){
            const char& c = s[i];
            if(isdigit(c)){
                haveDigit = true;
            }else if(isupper(c)){
                haveUpperLetter = true;
            }else if(islower(c)){
                haveLowerLetter = true;
            }else{
                haveOther = true;
            }

            if(i<s.size()-2){
                string substr = s.substr(i,3);
                if(subset.find(substr)!=subset.end()){//若该长度为3的子串重复
                    valid = false;
                    break;
                }else{
                    subset.insert(std::move(substr));
                }
            }
        }

        if(haveUpperLetter+haveLowerLetter+haveDigit+haveOther<3){
            valid = false;
        }

    }

    if(valid){
        cout<<"OK"<<endl;
    }else{
        cout<<"NG"<<endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
那一天的Java_J...:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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