题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include <stdio.h>
#include <string.h>
int repeatCheck(char* str, int index) //index>2
{
if(index<5) return 1;
char repeatChar[3];
for(int i=0;i<3;i++) repeatChar[i] = str[index-2+i];
// repeatChar[0]=str[index-2];
// repeatChar[1]=str[index-1];
// repeatChar[2]=str[index];
for(int i=0;i<=index-3;i++)
{
if(repeatChar[0]==str[i]
&& repeatChar[1]==str[i+1]
&& repeatChar[2]==str[i+2]) //出现等于3的连续重复子串
{
return 0;
}
}
return 1;
}
int main() {
char codeStr[100];
while (scanf("%s", codeStr) != EOF){
int rightF=0;
int codeLen = strlen(codeStr);
if(codeLen<=8) rightF=1;
else{
int numF=0, AF=0, aF=0, symF=0; //标志位
for(int i=0;i<codeLen;i++)
{
if(codeStr[i]>='0' && codeStr[i]<='9') numF=1;
else if(codeStr[i]>='a' && codeStr[i]<='z') aF=1;
else if(codeStr[i]>='A' && codeStr[i]<='Z') AF=1;
else symF=1;
if(!repeatCheck(codeStr,i)) rightF=1;
}
if(numF+aF+AF+symF<3) rightF=1;
}
if(rightF==0) printf("OK \n");
else printf("NG \n");
}
return 0;
}
老板电器公司氛围 197人发布
查看10道真题和解析