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

密码验证合格程序

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

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

int strtype(string str){
    int type = 0;
    int str_num = 0;
    int str_big = 0;
    int str_small = 0;
    int str_other = 0;
    for(int i = 0; i < str.size(); i++){
        if(str[i] >= '0' && str[i] <= '9') str_num = 1;
        else if(str[i] >= 'A' && str[i] <= 'Z') str_big = 1;
        else if(str[i] >= 'a' && str[i] <= 'z') str_small = 1;
        else str_other = 1;
    }
    type = str_num + str_big + str_small +str_other;
    return type;
}

int strrep(string str){
    set<string> hash_s;
    pair<set<string>::iterator, bool> ins_ret;
    string subs;
    for(int i = 0; i < str.size()-2; i++){
        subs = str.substr(i,3);
        ins_ret = hash_s.insert(subs);
        if(!ins_ret.second) return 0;
    }
    return 1;
}

int strexam(string str){
    if(str.size() <= 8) return 0;
    else if(strtype(str) < 3) return 0;
    else if(!strrep(str)) return 0;
    else return 1; 
}

int main() {
    string str;
    while(getline(cin, str)){
        strexam(str)?cout << "OK" << endl:cout << "NG" << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

烤点老白薯:这种东西到时候公众号搜索都有的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务