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

密码验证合格程序

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

#include <iostream>
#include <string>
#include<vector>
#include<numeric>
using namespace std;

int  is_rep(string str)
{int n=0;
    int len=str.size();
    for (int i=2;i<len-3;i++)
    for (int j=1;j<len-i-2;j++)
    { if(str[i-2]==str[i+j] && str[i-1]==str[i+j+1] && str[i]==str[i+j+2] )
    {n=1;break;}
    }
 if (n==1) {return 0;}
 else return 1;
}
    
int main()
{int upv[100]={0};
     int dov[100]={0};
      int     num[100]={0};
       int    other[100]={0};
    string str;
 vector<string>s;
   // cin>>str
    ////给不同密码类型分类记录
 while(cin>>str){
     if(str.size()<8){ cout<<"NG"<<endl;}
     else{
     for(int i=0;i<str.size();i++)
     { if (str[i]>='0' && str[i]<='9') {num[i]=1; }
      else if (str[i]>='a' && str[i]<='z') {dov[i]=1; }
      else if (str[i]>='A' && str[i]<='Z') {upv[i]=1; }
         else  {other[i]=1; }
     }
     int a=accumulate(upv,upv+100,0);
     int b=accumulate(dov,dov+100,0);
     int c=accumulate(num,num+100,0);
     int d=accumulate(other,other+100,0);
   //  cout<<a<<b<<c<<d;
 if(a!=0 && b!=0 && c!=0 && d!=0 && (is_rep(str))) {cout<<"OK"<<endl;}
 else if  (a!=0 && b!=0 && c!=0 && (is_rep(str))){cout<<"OK"<<endl;}
 else if  (a!=0 && b!=0  && d!=0 && (is_rep(str))){cout<<"OK"<<endl;}
 else if  (a!=0  && c!=0 && d!=0 && (is_rep(str))){cout<<"OK"<<endl;}
 else if  ( b!=0 && c!=0 && d!=0 && (is_rep(str))){cout<<"OK"<<endl;}
     // cout<<a<<b<<c<<d;
         else  cout<<"NG"<<endl;
 }
  // if (is_rep(str)) {cout<<"OK"<<endl;}
    
        }
}
#密码学工程师#
全部评论

相关推荐

不愿透露姓名的神秘牛友
08-20 19:41
那一天的Java_J...:简历完全流水账,学生思维很严重,还有很大的优化空间,可以多看看牛客的简历。
点赞 评论 收藏
分享
08-04 22:37
桂林学院 Java
行不行阿细GO:说真的我现在看到校招java简历都头痛。。千篇一律和阅卷高考作文差不多,估计公司也是吧,到最后就看学历和大厂实习了
投递BOSS直聘等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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