标签:输出 set Dictionary 单词 Andy world include define
Andy's First Dictionary
Description
不提英文了 直接上中文大意吧
XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英语。于是他每天都读一篇只包含生词的英语文章,并以自己高达450的智商在一秒钟之内记忆下来。
现在给你一篇XY学长今天要读的文章,请你写一个程序,输出他都学习到了哪些单词。
要求:如果文章中有相同的单词,那么仅仅输出一次;而且如果两个单词只有大小写不同,将他们视为相同的单词。
Input
测试数据将输入一篇文章。不超过5000行,每一行最多200个字符,并以EOF结束。
Output
按照字典序输出他学到的单词,每行输出一个单词,输出单词时所有的字母全部小写。
数据保证最多有5000个需要输出的单词。
Sample Input
Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the road. The sign read: "Disneyland Left."
So they went home.
Sample Output
a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when
Hint
输入可能包含标点符号,但标点符号显然不能算作单词的一部分。
题目链接:
https://vjudge.net/problem/UVA-10815
既然不重复,且按顺序排列,那自然是用set了。先一个一个读入单词,然后转小写,用字符串输入输出流存进set,然后遍历set即可
AC代码
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #include <sstream> #define mod 1000000007 #define ll long long #define INF 0x3f3f3f3f #define ME0(x) memset(x,0,sizeof(x)) using namespace std; set<string> world; set<string> ::iterator it; string s; int main() { while(cin>>s) { int len=s.length(); for(int i=0; i<len; i++) { if(isalpha(s[i]))//判断是否是英文字母 s[i]=towlower(s[i]); else s[i]=' '; } string buf; stringstream ss(s);//stringstream主要是用在將一个字符串分割,(遇到空格,回车)分割,方便统计、存入单词 while(ss>>buf) world.insert(buf); } for(it=world.begin();it!=world.end();it++)//遍历set cout<<*it<<endl; }
标签:输出,set,Dictionary,单词,Andy,world,include,define 来源: https://www.cnblogs.com/sky-stars/p/10988865.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。