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

密码验证合格程序

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

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

bool test(string s){
    if(s.length()<9) return false;
    set<string> st;
    for(char c:s){
        if(c==' ') continue;
        else if(c>='0'&&c<='9') st.insert("number");
        else if(c>='a'&&c<='z') st.insert("alpha");
        else if(c>='A'&&c<='Z') st.insert("ALPHA");
        else st.insert("other");
    }
    if(st.size()<3) return false;
    st.clear();
  //关键在这步,利用集合判重
    for(int i=2;i<s.length();i++){
        string now=s.substr(i-2,3);
        if(st.count(now)>0){
            return false;
        }
        st.insert(now);
    }
    return true;
}

int main() {
    string s;
    while(getline(cin,s)){
        if(test(s)) cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 14:22
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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