-
总时间限制:
- 1000ms 内存限制:
- 65536kB
-
描述
- 在一个字符串中找出元音字母a,e,i,o,u出现的次数。 输入
- 输入一行字符串(字符串中可能有空格,请用gets(s)方法把一行字符串输入到字符数组s中),字符串长度小于80个字符。 输出
- 输出一行,依次输出a,e,i,o,u在输入字符串中出现的次数,整数之间用空格分隔。 样例输入
-
If so, you already have a Google Account. You can sign in on the right.
样例输出
-
5 4 3 7 3
提示
- 注意,只统计小写元音字母a,e,i,o,u出现的次数。
问题链接:Bailian2688 求字母的个数
问题分析:(略)程序说明:边读入数据边处理,程序技巧要高一些,存储要能省则省。
读字符串到数组中再处理,那是倒腾!
看似无序的东西,放进数组后就可以使用循环进行处理。
AC的C语言程序如下:
/* Bailian2688 求字母的个数 */
#include <stdio.h>
#include <string.h>
#define N 5
char vowel[] = "aeiou";
int count[N];
int main(void)
{
char c;
int i;
// 数组清零
memset(count, 0, sizeof(count));
while((c = getchar()) != '\n' && c != EOF)
for(i=0; i<N; i++)
if(c == vowel[i]) {
count[i]++;
break;
}
for(i=0; i<N; i++)
printf("%d ", count[i]);
printf("\n");
return 0;
}