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

密码验证合格程序

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

#include <iostream>
using namespace std;

int main() {
    string str;
    while(cin>>str){
        int a=0,b=0,c=0,d=0,k=0;
        if(str.size()<=8){
            cout<<"NG"<<endl;
            continue;
        }
        bool flag=true;
        for(int i=0;i<str.size();i++){
            if(str[i]>='a'&&str[i]<='z'){
                if(!a)k++;
                a++;
            }
            else if(str[i]>='A'&&str[i]<='Z'){
                if(!b)k++;
                b++;
            }
            else if(str[i]>='0'&&str[i]<='9'){
                if(!c)k++;
                c++;
            }
            else {
                if(!d)k++;
                d++;
            }
            for(int j=i+3;j<str.size();j++){
                while(j<str.size()&&str[i]!=str[j])j++;

                int l=i,r=j,num=0;
                while(r<str.size()&&str[l]==str[r]){
                    //cout<<l<<" "<<r<<endl;
                    //cout<<str[l]<<" "<<str[r]<<endl;
                    l++,r++;
                    num++;
                }
                if(num>=3){
                    flag=false;
                    break;
                }
            }
            if(!flag){
                break;
            }
        }
        if(!flag){
            cout<<"NG"<<endl;
            continue;
        }
        if(k<3){
            cout<<"NG"<<endl;
            continue;
        }
        cout<<"OK"<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

三本咋了:觉得真的挺优秀的 实习title够了 ,字节实习跟agent不是很垂直 换个agent项目 差个机会,祈好运 ,有个教学类型的hello_agents 在github上面 感觉不太够用 (当然我还在学) ,你现在有好的项目了么,推荐一下呗
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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