华为oj 密码验证合格程序

来源:互联网 发布:淘宝厨房用品 编辑:程序博客网 时间:2024/06/04 08:39
#include<iostream>#include<string>#include<string.h>#include<vector>using namespace std;bool typeCheck(string s){const char *k = s.c_str();int count[4];memset(count,0,4*sizeof(int)); while((*k)!='\0'){     if(isdigit(*k))              count[0] = 1;         else if(isupper(*k))                count[1] = 1;              else if (islower(*k))                     count[2] = 1;                   else                     count[3] = 1;        ++k;} int last = count[0]+count[1]+count[2]+count[3];if(last>=3) return true;else  return false;}bool sameSubstr(string s){for(int i=0;i<s.size()-1;i++)   for(int j = i+1;j<s.size();j++)   {          int tempi = i;          int tempj = j;          int count = 0;  while(s[tempi] == s[tempj]&&tempi<s.size()&&tempj<s.size())  {       ++count;       if(count>2)          return true;       ++tempi;       ++tempj;  }   } return false;}int main(){string s;while(getline(cin,s)){//cout<<s<<endl;if(s.size()<=8)  cout<<"NG"<<endl;else{ if(typeCheck(s)) {    if(sameSubstr(s))                      cout<<"NG"<<endl;                   else                      cout<<"OK"<<endl;  } else   cout<<"NG"<<endl; } } return 0;} 

0 0