杭电 2027 统计元音

统计元音

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 46692    Accepted Submission(s): 19033


Problem Description
统计每个元音字母在字符串中出现的次数。
 


 

Input
输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串。
 


 

Output
对于每个测试实例输出5行,格式如下:
a:num1
e:num2
i:num3
o:num4
u:num5
多个测试实例之间由一个空行隔开。

请特别注意:最后一块输出后面没有空行:)
 


 

Sample Input
   
   
   
   
2 aeiou my name is ignatius
 


 

Sample Output
   
   
   
   
a:1 e:1 i:1 o:1 u:1 a:2 e:1 i:3 o:0 u:1
 

注意:这道题格式一逼的水,简直是个天坑orz。。。他说的所谓最后一行没有空格是多余的。输出的u后面还得带上。。。

 

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
 int n;
 scanf("%d",&n);
 getchar();           //记得写在n前面。。
 while(n){
  char str[110];
  gets(str);
  int a=0,b=0,c=0,d=0,e=0;
  int i;
  for(i=0;strlen(str)>i;i++){
   if(str[i]=='a') a++;
   else if(str[i]=='e') b++;
   else if(str[i]=='i') c++;
   else if(str[i]=='o') d++;
   else if(str[i]=='u') e++;
  }
  printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",a,b,c,d,e);          //最后的u后面一定要带\n啊啊啊啊。。。心塞。。
  n--;
  if(n==0) break;
  printf("\n");
 }
 return 0;
}

你可能感兴趣的:(杭电 2027 统计元音)