参考代码如下:
#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 人评分
C语言训练-计算1977!* (C++代码)浏览:857 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:1522 |
数组输出 (C语言代码)错误???浏览:565 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:936 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:326 |
1012题解浏览:869 |
1025题解浏览:738 |
矩阵乘方 (C语言代码)浏览:1031 |
复数求和 (C语言代码)浏览:927 |
判定字符位置 (C语言代码)浏览:799 |