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

密码验证合格程序

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

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

int main() {
    string str;
    while(cin >> str){
        int res = 1;
        if(str.length() <= 8){
            res = 0;
        }
        else{
            int numVar = 0;
            int Var[4] = {0};//四种字符类型的个数(q数字,1大写字母,2小写字母,3其他)
            for(int i = 0; i < str.length(); i++){
                if(str[i] >= '0' && str[i] <= '9') Var[0]++;
                else if(str[i] >= 'A' && str[i] <= 'Z') Var[1]++;
                else if(str[i] >= 'a' && str[i] <= 'z') Var[2]++;
                else Var[3]++;
            }
            for(int i = 0; i < 4; i++){
                if(Var[i]) numVar++;
            }
            if(numVar < 3){
                res = 0;
            }
            else{
                int left = 0;
                unordered_set<string> Set;
                while(left + 2 <= str.length()){
                    string tmp = str.substr(left, 3);
                    if(Set.count(tmp) != 0){
                        res = 0;
                        break;
                    }
                    else{
                        Set.insert(tmp);
                        left++;
                    }
                }
            }
        }
        if(res == 1) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}

全部评论

相关推荐

面试了几家,全程问项目,八股一点都不问,可惜准备了这么久
独角仙梦境:现在感觉问八股像是中场休息一样的,问几个八股放松一下再上强度
点赞 评论 收藏
分享
迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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