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

密码验证合格程序

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

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool judgeOK(string & s){
    int n=s.size();
    int flag=0;
    int tempf=0;
    if(n<8){
        return false;
    }
    /*判断类型*/
    for(int i=0;i<n;++i){
        if(s[i]>='0'&&s[i]<='9'){
            flag = flag|0x01;
        }else if(s[i]>='a'&&s[i]<='z'){
                    flag = flag|0x02;
        }else if(s[i]>='A'&&s[i]<='Z'){
                    flag = flag|0x04;
        }else{
            flag = flag|0x08;
        }
        /*判断重复(未完)*/


        if((i>1)){
            tempf = s.find(s.substr(i-2,3),i+1);
            if(tempf!=-1){
                // cout<<tempf;
                return false;
            }

        }
    }
        // cout<<flag<<endl;
    int sum=0;
    for(int j=0;j<4;++j){
        sum+=flag%2;
        flag/=2;
    }
    if(sum>2){
        return true;
    }
    return false;
}
int main() {
    string temp=" ";
    vector<string> rep;
    while (temp.size()) { // 注意 while 处理多个 case
        getline(cin,temp);
        rep.push_back(temp);
    }
    for(int i=0;i<rep.size()-1;++i){
                if(judgeOK(rep[i])){
            cout<<"OK"<<endl;
        }else{
            cout<<"NG"<<endl;
        }
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

05-26 09:07
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务