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

    http://acm.hdu.edu.cn/showproblem.php?pid=2027

    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
     
    代码:
    #include <bits/stdc++.h>
    
    using namespace std;
    
    char s[111];
    
    int main()
    {
        int n;
        cin>>n;
        getchar();
        for(int i=1;i<=n;i++)
        {
            int a=0,b=0,c=0,d=0,e=0;
            gets(s);
            int len = strlen(s);
            for(int i=0;i<len;i++)
            {
                if(s[i]=='a')
                    a++;
                else if(s[i]=='e')
                    b++;
                else if(s[i]=='i')
                    c++;
                else if(s[i]=='o')
                    d++;
                else if(s[i]=='u')
                    e++;
            }
            cout<<"a:"<<a<<endl;
            cout<<"e:"<<b<<endl;
            cout<<"i:"<<c<<endl;
            cout<<"o:"<<d<<endl;
            cout<<"u:"<<e<<endl;
            if(i!=n)
                cout<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    脚本——基础命令
    ELK 安装
    keepalived+lvs
    zabbix安装
    lnmp
    nagios安装
    nginx-tomcat动静分离
    课时五、boost与adaboost
    课时四、决策树和随机森林
    课时三、回归实践
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9221843.html
Copyright © 2011-2022 走看看