参考代码如下:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(void) { int M; scanf("%d", &M); int res[M]; //存放结果的数组 int index = 0; //数组下标 char str[50]; int i; for(i = 0; i < M; i++) { scanf("%s", str); int len = strlen(str); if (len < 8 || len > 16) { res[index++] = 0; } else { int hasup = 0; int haslow = 0; int hasnum = 0; int hasoth = 0; int j; for (j = 0; j < len; j++) { if (isupper(str[j])) hasup = 1; else if (islower(str[j])) haslow = 1; else if (isdigit(str[j])) hasnum = 1; else if (str[j] == '~' || str[j] == '!' || str[j] == '@' || str[j] == '#' || str[j] == '$' || str[j] == '%' || str[j] == '^') hasoth = 1; } //判断四类字符至少有三类,只要三个标志位总和大于等于3即可 int hassum = hasup + haslow + hasnum + hasoth; if (hassum >= 3) res[index++] = 1; else res[index++] = 0; } memset(str, 0, 50); //清空数组 } //输出结果 int k; for (k = 0; k < index; k++) { if (res[k] == 1) printf("YES\n"); else printf("NO\n"); } return 0; }
0.0分
0 人评分
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:708 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:823 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:494 |
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:927 |
C语言程序设计教程(第三版)课后习题8.2 (Java代码)浏览:2269 |
C语言训练-数字母 (C语言代码)浏览:582 |
C语言程序设计教程(第三版)课后习题8.6 (C语言代码)浏览:562 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:262 |
a+b浏览:432 |
1025题解浏览:732 |