HDU2027 统计元音

【题目】


【思路】

【代码】AC的C++代码如下:

#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main()
{
    int n,i,j;
    char vowel[] = "aeiou";
    int count[5];
    char s[101];
    cin >> n;
    getchar();
    for (i = 0;i < n;i++)
    {
        gets(s);
        memset(count,0,sizeof(count));
        j = 0;
        while (s[j] != '\0')
        {
            for (int k = 0;k < 5;k++)
            {
                if (s[j] == vowel[k])
                {
                    count[k]++;
                }
            }
            j++;
        }

        if (i != 0)
            cout << endl;
        for (int k = 0;k < 5;k++)
        {
            cout << vowel[k] << ":" << count[k] << endl;
        }
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/m0_38056893/article/details/80032001