输入一行字符,分别统计出包含英文字母、空格、数字和其它字符的个数。
数据范围:输入的字符串长度满足1≤n≤1000
输入描述:输入一行字符串,可以有空格
输出描述:统计其中英文字符,空格字符,数字字符,其他字符的个数
输入:1qazxsw23 edcvfr45tgbn hy67uj m,ki89ol.\/;p0-=\][
输出:
26
3
10
12
#include<stdio.h>
#include<string.h>
int main() {char str[1001] = {'\0'};while (gets(str)) {int len = strlen(str);int charac = 0, blank = 0, num = 0, other = 0;for (int i = len - 1; i >= 0; i--) {//字母计数(区分大小写)if ((('a' <= str[i])&&(str[i] <= 'z')) || (('A' <= str[i])&&(str[i] <= 'Z'))) charac++;else if (str[i] == ' ') blank++; //空格计数else if (('0' <= str[i]) && (str[i] <= '9')) num++; //数字计数else other++; //其他字符计数}printf("%d\n%d\n%d\n%d\n", charac, blank, num, other);}
}