统计每个元音字母在字符串中出现的次数,用c语言,输入第一行包含一个整数T小于100。每组测试数据占一行,包含一个不长于100的字符串
时间: 2023-05-20 14:02:52 浏览: 51
ChatGPT: 当然可以,以下是代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
int T;
scanf("%d", &T);
while (T--) {
char str[105];
scanf("%s", str);
int cnt[5] = {0}; // a, e, i, o, u
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] == 'a') cnt[0]++;
else if (str[i] == 'e') cnt[1]++;
else if (str[i] == 'i') cnt[2]++;
else if (str[i] == 'o') cnt[3]++;
else if (str[i] == 'u') cnt[4]++;
}
printf("%d %d %d %d %d\n", cnt[0], cnt[1], cnt[2], cnt[3], cnt[4]);
}
return 0;
}
```
请问还有什么问题吗?