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

密码验证合格程序

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

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

bool Password_Type(string password){
    int big=0,small=0,num=0,other=0;
    for (auto x:password) {
        if(isdigit(x)) num=1;
        else if (isupper(x)) big=1;
        else if (islower(x)) small=1;
        else if (x!=' '||x!='\n') other=1;
    }
    if (big+small+num+other>=3) {return true;}
    else return false;
}

bool Same_SubString(string password){
    map<string,int> m;
    string A;
    for(int i=0;i<=password.length()-3;++i){
        A=password.substr(i,3);
        m[A]+=1;
    }
    for(auto x:m){
        if(x.second==2) return false;
    }
    return true;
}

int main() {
    string key;
    while (cin>>key) {
        if(key.length()<=8||!Password_Type(key)||!Same_SubString(key)) 
            cout<<"NG"<<endl;
        else{cout<<"OK"<<endl;}
    }
    return 0;
}

全部评论

相关推荐

01-02 16:50
门头沟学院 Java
不放弃的小鱼干很洒脱:比kpi面面完了也不发感谢信全靠自己猜的好多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务