解题思路:
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 人评分
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
DNA (C语言描述,数据结构)浏览:856 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:634 |
简单的a+b (C语言代码)浏览:606 |
1113题解浏览:789 |
复数求和 (C语言代码)浏览:927 |
盐水的故事 (C语言代码)浏览:1529 |
小O的图案 (C语言代码)浏览:915 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:471 |
C二级辅导-公约公倍 (C语言代码)浏览:663 |