题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2027
算法分析:注意输出,计算n的个数控制‘\n’数量
我的ac代码:
#include <stdio.h> int main() { int n, num[6]; char a[100], word[6] = {'0', 'a', 'e', 'i', 'o', 'u'}; while (scanf("%d", &n) != EOF) { getchar(); while (n--) { for (int i = 0; i <= 5; i++) { num[i] = 0; } a[0]='\0'; gets(a); for (int i = 0; a[i] != '\0'; i++) { if (a[i] == 'a') { num[1]++; } else if (a[i] == 'e') { num[2]++; } else if (a[i] == 'i') { num[3]++; } else if (a[i] == 'o') { num[4]++; } else if (a[i] == 'u') { num[5]++; } } for (int j = 1; j <= 5; j++) { printf("%c:%d\n", word[j], num[j]); } if(n-1>=0){ printf("\n"); } } } return 0; }