C刷题记录-1012
题目描述
输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。
输入
一行字符
输出统计值
样例输入
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
样例输出
23 16 2 4
1 #include <stdio.h> 2 3 int main(){ 4 char ch; 5 int number_ch = 0, number_num = 0,number_space = 0,number_other_ch = 0; 6 7 while ( (ch = getchar())!= '\n') 8 { 9 if ((ch>= 'a'&& ch <='z') || (ch >='A'&&ch<='Z')) 10 { 11 number_ch ++; 12 } 13 else if(ch >= '0' && ch <= '9') 14 { 15 number_num ++; 16 } 17 else if (ch == ' ') 18 { 19 number_space ++; 20 } 21 else 22 { 23 number_other_ch ++; 24 } 25 } 26 printf("%d %d %d %d",number_ch,number_num,number_space,number_other_ch); 27 return 0; 28 }