zoukankan      html  css  js  c++  java
  • 统计元音

    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
     
     
    code:

    #include<stdio.h>
    #include<string.h>
    int main()
    {
            int n,i,s1,s2,s3,s4,s5,len;
           char str[100];
           while(scanf("%d%*c",&n)!=EOF)
           {
                while(n--)                                        //不能用for(i=0;i<n;i++)
                {
                        gets(str);
                        len=strlen(str);
                        s1=s2=s3=s4=s5=0;
                        for(i=0;i<len;i++)
                        {
                                if(str[i]=='a')
                                      s1++;
                                if(str[i]=='e')
                                      s2++;
                                if(str[i]=='i')
                                      s3++;
                                if(str[i]=='o')
                                      s4++;
                               if(str[i]=='u')
                                      s5++;
                      }

              printf("a:%d e:%d i:%d o:%d u:%d ",s1,s2,s3,s4,s5);
         if(n!=0)
             printf(" ");

               }
         }
      return 0;
    }

      

     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    最难的事
    性格决定命运,习惯决定未来
    系统构架师之路
    时间是经不起浪费的
    如何投资自己,增加自身价值!
    最好的程序员大多是自学成才的
    杂记
    Win7启动Oracle出错
    推荐代码生成器工具排行
    Hibernate 与 Oracle 11g 的问题
  • 原文地址:https://www.cnblogs.com/gongpulin/p/3899633.html
Copyright © 2011-2022 走看看