1192 - C语言7.16
给出一篇文章,共有3行文字,每行有最多80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格以及其他字符的个数。
Input
共有3行,表示输入的文章。
Output
在一行中输出文章中的英文大写字母、小写字母、数字、空格以及其他字符的个数,用空格隔开。
请注意行尾输出换行。
Examples
Input
I am a program. This is the second line! And this is the last line........
Output
3 47 0 12 10
Solution C
#include <stdio.h> int main() { char p[3][81]; int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0; for (i = 0;i < 3;i++) { gets(p[i]); } for (i = 0;i < 3;i++) { for (j = 0;p[i][j] != '\0';j++) { if ('A' <= p[i][j] && p[i][j] <= 'Z') upper++; else if ('a' <= p[i][j] && p[i][j] <= 'z') lower++; else if ('0' <= p[i][j] && p[i][j] <= '9') digit++; else if (p[i][j] == ' ') space++; else other++; } } printf("%d %d %d %d %d\n", upper, lower, digit, space, other); return 0; }
Solution C++
#include <stdio.h> int main() { char p[3][81]; int i, j, upper = 0, lower = 0, digit = 0, space = 0, other = 0; for (i = 0;i < 3;i++) { gets(p[i]); } for (i = 0;i < 3;i++) { for (j = 0;p[i][j] != '\0';j++) { if ('A' <= p[i][j] && p[i][j] <= 'Z') upper++; else if ('a' <= p[i][j] && p[i][j] <= 'z') lower++; else if ('0' <= p[i][j] && p[i][j] <= '9') digit++; else if (p[i][j] == ' ') space++; else other++; } } printf("%d %d %d %d %d\n", upper, lower, digit, space, other); return 0; }