码迷,mamicode.com
首页 > 其他好文 > 详细

统计元音

时间:2014-10-27 16:57:22      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   color   ar   sp   数据   div   

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())!=\n){
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\n",a_amount);
40         printf("e:%d\n",e_amount);
41         printf("i:%d\n",i_amount);
42         printf("o:%d\n",o_amount);
43         printf("u:%d\n",u_amount);
44          
45         if(n!=0)
46             printf("\n");
47     }
48              
49     return 0;
50 }

 

统计元音

标签:des   style   blog   io   color   ar   sp   数据   div   

原文地址:http://www.cnblogs.com/zqxLonely/p/4054319.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!