题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
重点是判断重复子串,只需要判断长度为3的字串是否有重复,沿着原字符串线性往后比较判断
/*HW字符串操作2*/
#include <bits/stdc++.h>
using namespace std;
string s;
bool kind4()
{
int flag[4];
for(int i=0;i<4;i++)flag[i]=0;
for(int i=0;i<s.length();i++){
if(isdigit(s[i]))flag[0]=1;
if(s[i]>='a'&&s[i]<='z')flag[1]=1;
if(s[i]>='A'&&s[i]<='Z')flag[2]=1;
if(!( isdigit(s[i]) || (s[i]>='a'&&s[i]<='z') || (s[i]>='A'&&s[i]<='Z') ))flag[3]=1;
if(flag[0]+flag[1]+flag[2]+flag[3]>=3)return true;
}
return false;
}
bool nonappear3()
{
for(int i=0;i<=s.length()-6;i++){
for(int j=i+3;j<=s.length()-3;j++){
if(s[i]==s[j]&&s[i+1]==s[j+1]&&s[i+2]==s[j+2]){
return false;
}
}
}
return true;
}
int main() {
while(cin>>s){
if(s.length()>8 && kind4() && nonappear3() ){
cout<<"OK"<<endl;
}else{
cout<<"NG"<<endl;
}
}
}
// 64 位输出请用 printf("%lld")