统计元音

Problem Description

统计每个元音字母在字符串中出现的次数。

Input

输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。

Output

对于每个测试实例输出5行,格式如下:

a:num1

e:num2

i:num3

o:num4

u:num5

多个测试实例之间由一个空行隔开。

请特别注意:最后一块输出后面没有空行:)

Sample Input

2

aeiou

my name is ignatius

Sample Output

a:1

e:1

i:1

o:1

u:1

a:2

e:1

i:3

o:0

u:1

 1 #include <stdio.h>
 2  
 3 int main(){
 4     int n;
 5     char c;
 6     int a_amount;
 7     int e_amount;
 8     int i_amount;
 9     int o_amount;
10     int u_amount;
11      
12     scanf("%d",&n);
13     getchar();
14      
15     while(n--){
16         a_amount=0;
17         e_amount=0;
18         i_amount=0;
19         o_amount=0;
20         u_amount=0;
21          
22         while((c=getchar())!='
'){
23             if(c=='a')
24                 a_amount++;
25                  
26             else if(c=='e')
27                 e_amount++;
28                  
29             else if(c=='i')
30                 i_amount++;
31                  
32             else if(c=='o')
33                 o_amount++;
34                  
35             else if(c=='u')
36                 u_amount++;
37         }
38          
39         printf("a:%d
",a_amount);
40         printf("e:%d
",e_amount);
41         printf("i:%d
",i_amount);
42         printf("o:%d
",o_amount);
43         printf("u:%d
",u_amount);
44          
45         if(n!=0)
46             printf("
");
47     }
48              
49     return 0;
50 }
原文地址:https://www.cnblogs.com/zqxLonely/p/4054319.html