HDU2027 统计元音

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn = 205; //此处注意字符的ASCII码取值范围
 6 char s[maxn];
 7 int hash1[maxn];
 8 int main()
 9 {
10     int  n, flag;
11     scanf("%d", &n);
12     getchar(); //吃掉第一个回车
13     while(n--)
14     {
15         gets(s);
16         int len = strlen(s);
17         memset(hash1, 0, sizeof(hash1)); //别忘记初始化
18         for(int i = 0; i < len; i++) hash1[s[i]]++;
19         printf("a:%d
e:%d
i:%d
o:%d
u:%d
",hash1['a'], //字母要加单引号
20                hash1['e'],hash1['i'],hash1['o'],hash1['u']);
21         if(n) printf("
"); //最后一组数据后没有空行
22     }
23     return 0;
24 }
View Code
原文地址:https://www.cnblogs.com/loveprincess/p/4819260.html