HDU_oj_2027 统计元音

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
 
分析:
注意点:
用gets()函数接收字符串,由于gets()函数会接收到前面输入数字n时的回车符,
所以在get()前需要用getchar()函数吸收这个回车符
 
 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     char *ss,s[100];
 7     int n,na,ne,ni,no,nu;
 8     cin>>n;
 9     getchar();
10     while(n--)
11     {
12         gets(s);
13         ss=s;
14         na=ne=ni=no=nu=0;
15         while(*ss!='\0')
16         {
17             if(*ss=='a')
18             na++;
19             else if(*ss=='e')
20             ne++;
21             else if(*ss=='i')
22             ni++;
23             else if(*ss=='o')
24             no++;
25             else if(*ss=='u')
26             nu++;
27             ss++;
28         }
29         cout<<"a:"<<na<<endl;
30         cout<<"e:"<<ne<<endl;
31         cout<<"i:"<<ni<<endl;
32         cout<<"o:"<<no<<endl;
33         cout<<"u:"<<nu<<endl;
34         if(n)
35         cout<<endl;
36     }
37 }

 

转载于:https://www.cnblogs.com/tenjl-exv/p/7993913.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值