您的位置:首页 > 其它

第十三周 OJ平台-统计元音字母个数

2014-11-20 15:08 387 查看

题目描述

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

输入

输入一行长度不超过100的字符串。

输出

输出各个元音字母出现的次数,格式是(numx是数字):

a:num1

e:num2

i:num3

o:num4

u:num5



问题及代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main( )
{
    char str[100];
    int j=0,A=0,E=0,I=0,O=0,U=0;
    gets(str);
    while(str[j]!='\0')
    {
        if (str[j]=='a')
            A++;
        else if (str[j]=='e')
            E++;
        else if (str[j]=='i')
            I++;
        else if (str[j]=='o')
            O++;
        else if (str[j]=='u')
            U++;
        j++;
    }
    cout<<"a:"<<A<<endl;
    cout<<"e:"<<E<<endl;
    cout<<"i:"<<I<<endl;
    cout<<"o:"<<O<<endl;
    cout<<"u:"<<U<<endl;
    return 0;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: