统计元音HDU - 2027 1周赛I

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

Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。

Output
对于每个测试实例输出5行,格式如下:

a:num1

e:num2

i:num3

o:num4

u:num5

多个测试实例之间由一个空行隔开。

请特别注意:最后一块输出后面没有空行:)

#include <iostream>
using namespace std;

int main()
{
	char f[1200];
	int c;
	char b[5] = { 'a','e','i','o','u' };
	cin >> c;
	getchar();
	for ( int i = 0; i < c; i++)
	{
		int a[5] = { 0 };
		cin.getline(f, 100);
		for (int l = 0; f[l] != '\0'; l++)
		{
			if (f[l] == 'a') a[0] ++;
			if (f[l] == 'e' ) a[1]++;
			if (f[l] == 'i')a[2]++;
			if (f[l] == 'o' )a[3]++;
			if (f[l] == 'u' ) a[4]++;
			
		}
		
		for (int j = 0; j < 5; j++)
			cout << b[j] << ":" << a[j] << endl;
   if (i!=c - 1) cout << endl;
   

	}

	

}

[http://acm.hdu.edu.cn/showproblem.php?pid=2027]

猜你喜欢

转载自blog.csdn.net/weixin_44008424/article/details/85010861