lee


私信TA

用户名:lotus

访问量:3293

签 名:

等  级
排  名 30238
经  验 459
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:

1. 只能包含四种数据,那就需要对应四组数据的检查函数,前三个有库函数,只需要写一个最后的特殊字符检查。

2. 由于四中符号的检查过程相同,可以利用转移表简化代码。



注意事项:

转移表的定义与使用。

参照《C和指针》p263。



参考代码:


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>


//特殊字符数组

char arrGraph[] = "~!@#$%^";


//创建检查特殊数组的函数

int isGraph(int ch)

{

    int totalLength = strlen(arrGraph);

    for(int i = 0; i < totalLength; i++)

    {

        if(ch == arrGraph[i])

            return 1;

    }

    return 0;

}


//转移表 函数指针数组 《C和指针》p263

static int (*testFunc[])(int) =

{

    isupper,

    islower,

    isdigit,

    isGraph

};


#define N_CATEGORYS ((sizeof(testFunc))/(sizeof(testFunc[0])))

#define N_LENGTHMIN 8

#define N_LENGTHMAX 16


int main()

{

    int M;

    if((scanf("%d",&M))!=1)

    {

        printf("Wrong input number\n");

        return 0;

    }

    

    int m;

    //char *password[100];

    for(m = 0; m < M; m++)

    {

        char password[100];

        if(scanf("%s",password) !=1 )

        {

            printf("Wrong input number\n");

            return 0;

        }

        int lengthPass = (int)strlen(password);

        

        if(lengthPass >= 8 && lengthPass <= 16)

        {

            int count[N_CATEGORYS] = {0};

            int sumResult = 0;

            for(int i = 0; i < lengthPass; i++)

            {

                for(int n = 0; n < N_CATEGORYS; n++)

                {

                    if((count[n] !=1 ) && (testFunc[n](password[i])))

                    {

                        count[n] = 1;

                    }

                }

            }

            for(int n = 0; n < N_CATEGORYS; n++)

            {

                sumResult += count[n];

            }

            if(sumResult >= 3)

            {

                printf("YES\n");

            }

            else

            {

                printf("NO\n");

            }

        }

        else

        {

            printf("NO\n");

        }

    }

}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区