1012: C语言程序设计教程(第三版)课后习题6.2

题目描述

输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。

输入

一行字符

输出

统计值

样例输入

aklsjflj123 sadf918u324 asdf91u32oasdf/.';123

样例输出

23 16 2 4

 1 #include "stdio.h"
 2 
 3 int main(int argc, char const *argv[])
 4 {
 5     char s[81];
 6     int i, char_count = 0, num_count = 0, space_count = 0, other_count = 0;
 7     // scanf("%s", s);
 8     gets(s);
 9 
10     for(i = 0; s[i] != '\0'; i++)
11     {
12         if(s[i] >= 'A' && s[i] <= 'Z' || s[i] >= 'a' && s[i] <= 'z')
13             char_count ++;
14         else if(s[i] >= '0' && s[i] <= '9')
15             num_count ++;
16         else if(s[i] == ' ')
17             space_count ++;
18         else
19             other_count ++;
20     }
21 
22     printf("%d %d %d %d\n", char_count, num_count, space_count, other_count);
23     return 0;
24 }

 

posted @ 2017-11-13 18:57  大波非猫  阅读(571)  评论(0编辑  收藏  举报