题解 | #密码验证合格程序#
密码验证合格程序
https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
#include<stdio.h>
#include<string.h>
int main(){
char str[101];
int len,len1,i,j,flag1,flag2,flag3;
int upper,lower,num,other;
while(gets(str)){
upper=lower=num=other=0;
flag1=flag2=flag3=1;
len=strlen(str);
//判断条件一
if(len<=8)
flag1=0;
//判断条件二
for(i=0;i<len;i++)
{
if(str[i]>='0'&&str[i]<='9')
num=1;
else if(str[i]>='A'&&str[i]<='Z')
upper=1;
else if(str[i]>='a'&&str[i]<='z')
lower=1;
else if(str[i]!='\0'&&str[i]!=' ')
other=1;
}
if(num+upper+lower+other<3)
flag2=0;
//判断条件三
for(i=0;i<len-2;i++)
{
for(j=i+1;j<len-2;j++)
{
if(str[i]==str[j])
{
len1=1;
while(str[i+len1]==str[j+len1])
len1++;
if(len1>2)
{
flag3=0;
break;
}
}
}
}
if(flag1+flag2+flag3==3)
printf("OK\n");
else
printf("NG\n");
}
return 0;
}
