zoukankan      html  css  js  c++  java
  • [YTU]_2759( 字符串---统计元音)

    Description

    输入一行字符串,统计每个元音字母在字符串中出现的次数。

    Input

    输入长度不超过100的字符串。

    Output

    输出5行,格式如下: a:a元音字母在字符串中出现的次数e:e元音字母在字符串中出现的次数 i:i元音字母在字符串中出现的次数o:o元音字母在字符串中出现的次数u:u元音字母在字符串中出现的次数

    Sample Input

    my name is ignatius

    Sample Output

    a:2
    e:1
    i:3
    o:0
    u:1
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
        char string1[101];
        int i,a=0,b=0,c=0,d=0,e=0;
        gets(string1);
        for(i=0;string1[i]!='';i++)
        {
            if(string1[i]=='a')
                a++;
            if(string1[i]=='e')
               b++;
            if(string1[i]=='i')
               c++;
            if(string1[i]=='o')
               d++;
            if(string1[i]=='u')
               e++; 
           }
        cout<<"a:"<<a<<endl<<"e:"<<b<<endl<<"i:"<<c<<endl<<"o:"<<d<<endl<<"u:"<<e<<endl;
        return 0;
    }
    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
    	char str[101];
    	int i,q=0,w=0,y=0,r=0,p=0;
    	gets(str);
    	for(i=0;str[i]!='';i++)
    	{
    		switch(str[i])
    		{
    		case 'a':q++;break;
    		case 'e':w++;break;
    		case 'i':r++;break;
    		case 'o':y++;break;
    		case 'u':p++;break;
    		case 'A':q++;break;
    		case 'E':w++;break;
    		case 'I':r++;break;
    		case 'O':y++;break;
    		case 'U':p++;break;
    		}
    	}
    		cout<<"a:"<<q<<endl<<"e:"<<w<<endl<<"i:"<<r<<endl<<"o:"<<y<<endl<<"u:"<<p<<endl;
    	return 0;
    }


  • 相关阅读:
    struct pack unpack
    读书笔记 第四章&第五章
    The Sieve of Eratosthens(爱拉托逊斯筛选法)
    2013年3月百度之星A题
    2013年3月百度之星B题
    好句子
    BFS 与 DFS
    记录本
    HDU 2028 如何计算最小公倍数?
    HDU 2015 偶数求和 解题报告
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586405.html
Copyright © 2011-2022 走看看