统计元音(stringstream的-应用)

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

话说“请特别注意:最后一块输出后面没有空行”到底怎样擦算啊?我去

 1 #include<iostream>
 2 #include<iomanip>
 3 //#include<bits/stdc++.h>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<sstream>
 7 #define PI  3.14159265358979
 8 #define LL long long
 9 #define  eps   0.00000001
10 #define LL long long
11 using namespace std;
12 int main()
13 {
14     //freopen("input.txt","r",stdin);
15       char c[110];
16       int T;
17       cin>>T;
18       getchar();//吸收回车
19       while(T--)
20       {
21           gets(c);
22           stringstream ss(c);//复制
23           string s;int sum1=0,sum2=0,sum3=0,sum4=0,sum5=0;
24           while(ss>>s)//ss->s
25           {
26               int l=s.size();
27               for(int i=0;i<l;++i)
28               {
29                   if(s[i]==‘a‘) ++sum1;
30                   if(s[i]==‘e‘) ++sum2;
31                   if(s[i]==‘i‘) ++sum3;
32                   if(s[i]==‘o‘) ++sum4;
33                   if(s[i]==‘u‘) ++sum5;
34               }
35           }
36           cout<<"a:"<<sum1<<endl;
37           cout<<"e:"<<sum2<<endl;
38           cout<<"i:"<<sum3<<endl;
39           cout<<"o:"<<sum4<<endl;
40           if(T!=0) cout<<"u:"<<sum5<<endl<<endl;
41           else cout<<"u:"<<sum5<<endl;
42       }
43 }

原文地址:https://www.cnblogs.com/Auroras/p/10800188.html

时间: 2024-08-29 00:30:50

统计元音(stringstream的-应用)的相关文章

1166: 零起点学算法73——统计元音

1166: 零起点学算法73--统计元音 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 1082  Accepted: 402[Submit][Status][Web Board] Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串,只由小写字母组成. Output 对于每个测试实例输出5行

c语言之统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45249    Accepted Submission(s): 18458 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

HDOJ 2027 统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37878    Accepted Submission(s): 15559 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

hdu 2027 统计元音

统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 58391    Accepted Submission(s): 23254 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数据首先包括一个整数n,表示测试实例的个数,然后是n行长度不超过100的字符串. Output 对于每个测

统计元音

http://acm.hdu.edu.cn/showproblem.php?pid=2027 1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 int main() 5 { 6 int n; 7 char a[102]; 8 scanf("%d",&n); 9 getchar(); 10 while(n--) 11 { 12 gets(a); 13 int l

hdu 2027 统计元音 (java)

问题: 注意for循环中参数,不要搞混了. 注意空行和换行的区别,题目是讲的不空行,但还是要进行换行. 统计元音 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45831    Accepted Submission(s): 18695 Problem Description 统计每个元音字母在字符串中出现的次数. Input 输入数

百度练习题 统计元音字母

题目如下: 遇到一道题,苦苦没有思路,求各路python大神解答,在线等.输入一串文字,统计这串文字里的[元音字母(aeiou)大小写不分,A和a都统一算是a]的数量.有3个要求:1.打印出出现次数最少的元音字母和它的出现次数,如果出现次数为0的话就忽略不急.例如,“Are you about ”,里面没出现i, i就不算了.所以它打出来的东西就是“e with 1 occurence.”2.类似于“Andy was here”,a 和 e 都是出现次数最少的元音字母(2次),那么打出来就得是

统计元音(hdu20)

输入格式:输入一个整型,再循环输入带空格的字符串. 思考:先用scanf()函数输入一个整型,后面直接来个大循环,带空格字符串输入直接用gets()函数. 注意:由于scanf()里面多加了%c,&d,所以大循环前不用getchar()函数. #include<stdio.h> #include<cstring> int main() { int n; char d; char c[101]; while (scanf_s("%d%c", &n,

Problem K: 零起点学算法107——统计元音

#include<stdio.h> int main() { int n; char a[100]; while(scanf("%d%*c",&n)!=EOF) { while(n--) { int num1=0,num2=0,num3=0,num4=0,num5=0; gets(a); for(int i=0;a[i]!='\0';i++) { switch(a[i]) //在这用switch语句会比较方便 { case 'a': num1++;break; ca