题解 | 密码验证合格程序

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

#include <stdio.h>

#include <string.h>

#include <stdbool.h>

bool isLegal(char* s)

{

char* p=s;

char p1[4];

int chartype[4];

int i=0,nums=0;

memset(chartype,0,sizeof(int)*4);

if(strlen(s)<8)

return false;

while(*p != '\0')

{

if(*p>='A' && *p<='Z')

(chartype[0])++;

else if(*p>='a' && *p<='z')

(chartype[1])++;

else if(*p>='0' && *p<='9')

(chartype[2])++;

else

(chartype[3])++;

if(*p && *(p+3))

{

strncpy(p1, p, 3);

p1[3]='\0';

if(strstr(p+3,p1))

return false;

}

p++;

}

for(i=0;i<4;i++)

{

if(chartype[i])

nums++;

}

if(nums>=3)

return true;

else

return false;

}

int main() {

char code[10][101];

int result[10];

int num=0;

int i;

memset((char*)code,0,sizeof(char)*10*101);

while(scanf("%s",code[num])!=EOF)

{

num++;

}

for(i=0;i<num;i++)

{

if(isLegal(code[i]))

{

printf("OK\r\n");

}

else {

printf("NG\r\n");

}

}

return 0;

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务