hdu 2027 统计元音

统计元音

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 58391    Accepted Submission(s): 23254

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 #include <string.h>
 3 int main(){
 4     int test;
 5     int num_a,num_e,num_i,num_o,num_u;  
 6     scanf("%d", &test);
 7     getchar();//特别注意,用一个getchar吃掉输入测试组数后的那个回车,防止用gets或者getline时将回车当成字符串
 8     while(test--){
 9         num_a=num_e=num_i=num_o=num_u=0;
10         char s[101];
11         gets(s);
12         int len = strlen(s);
13         for(int i = 0; i < len; i++){
14             switch(s[i]){
15                 case 'a': num_a++; break;
16                 case 'e': num_e++; break;
17                 case 'i': num_i++; break;
18                 case 'o': num_o++; break;
19                 case 'u': num_u++; break;
20             }
21         }
22         printf("a:%d
e:%d
i:%d
o:%d
u:%d
",num_a,num_e,num_i,num_o,num_u);
23         if(test){
24             printf("
");
25         }
26             
27     }
28     return 0;
29 } 
原文地址:https://www.cnblogs.com/qinduanyinghua/p/5559171.html