原创作品 转载请注明出处http://blog.youkuaiyun.com/always2015/article/details/45531523
简单题,主要知道元音字母有哪些,就很容易通过if语句计算出来。我的AC代码如下:
#include <iostream>
#include<string>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(void)
{
string input_str;
int n,lenght,flag[5]= {0};
char vowel[]= {'a','e','i','o','u'};
cin>>n;
//获取回车,否则出错
getchar();
for(int h=0; h<n; h++)
{
//获取整行字符串
getline(cin,input_str);
//获取长度
lenght=input_str.size();
//统计出现的次数
for(int i=0; i<lenght; i++)
{
if(input_str[i]==vowel[0])
++flag[0];
if(input_str[i]==vowel[1])
++flag[1];
if(input_str[i]==vowel[2])
++flag[2];
if(input_str[i]==vowel[3])
++flag[3];
if(input_str[i]==vowel[4])
++flag[4];
}
//格式输出
for(int j=0; j<5; j++)
cout<<vowel[j]<<":"<<flag[j]<<endl;
//最后一个测试用例不用空行
if(h<n-1)
cout<<endl;
//重新清零
memset(flag,0,5*sizeof(int));
}
return 0;
}