首页 > 题解 | #密码验证合格程序#
头像
牛客425462286号
发布于 2022-07-23 22:12
+ 关注

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

#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;}
    
        }
}

全部评论

(0) 回帖
加载中...
话题 回帖