[YTU]_2759( 字符串---统计元音)
生活随笔
收集整理的這篇文章主要介紹了
[YTU]_2759( 字符串---统计元音)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
輸入一行字符串,統計每個元音字母在字符串中出現的次數。
Input
輸入長度不超過100的字符串。
Output
輸出5行,格式如下: a:a元音字母在字符串中出現的次數e:e元音字母在字符串中出現的次數 i:i元音字母在字符串中出現的次數o:o元音字母在字符串中出現的次數u:u元音字母在字符串中出現的次數
Sample Input
my name is ignatiusSample 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]!='\0';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]!='\0';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; }《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀
總結
以上是生活随笔為你收集整理的[YTU]_2759( 字符串---统计元音)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_1998( C语言实验——
- 下一篇: [YTU]_2760( 字符串---首字