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

密码验证合格程序

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

#include <iostream>
#include <map>

using namespace std;

int main(){
    string str;
    while (cin>>str){
        map<string,int> sub;
        bool flag = 1;
        int ch[4] = {0};
        int n = str.size();
        if (n>8){
            for (int i = 0; i < n; ++i) {
                if (str[i]>='a'&&str[i]<='z') ch[0] = 1;
                else if (str[i]>='A'&&str[i]<='Z') ch[1] = 1;
                else if (str[i]>='0'&&str[i]<='9') ch[2] = 1;
                else ch[3] = 1;

                if (sub.find(str.substr(i,3)) != sub.end()){
                    // 不能有长度大于2的包含公共元素的子串重复
                    flag = false;
                } else{
                    sub[str.substr(i,3)] = 1;
                }
            }
            int count = 0;
            for (int j = 0; j < 4; ++j) {
                if (ch[j]) count++;
            }
            if (count<3){
                // 不同字符数不足
                flag = false;
            }
        }
        else{
            // 长度不足
            flag = false;
        }
        if (flag){
            cout<<"OK"<<endl;
        } else{
            cout<<"NG"<<endl;
        }
    }
    return 0;
}

全部评论

相关推荐

09-01 11:31
门头沟学院 Java
buul:七牛云的吧,感觉想法是好的,但是大家没那么多时间弄他这个啊。。。不知道的还以为他是顶尖大厂呢还搞比赛抢hc,只能说应试者的痛苦考察方是无法理解的,他们只会想一出是一出
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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