Description

Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. From his bookshelf he would pick one of his favourite story books, from which he would copy out all the distinct words. By arranging the words in alphabetical order, he is done! Of course, it is a really time-consuming job, and this is where a computer program is helpful.

You are asked to write a program that lists all the different words in the input text. In this problem, a word is defined as a consecutive sequence of alphabets, in upper and/or lower case. Words with only one letter are also to be considered. Furthermore, your program must be CaSe InSeNsItIvE. For example, words like "Apple", "apple" or "APPLE" must be considered the same.

Input

The input file is a text with no more than 5000 lines. An input line has at most 200 characters. Input is terminated by EOF.

Output

Your output should give a list of different words that appears in the input text, one in a line. The words should all be in lower case, sorted in alphabetical order. You can be sure that he number of distinct words in the text does not exceed 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
解题思路:题目的意思就是读取文本中每个单词(只由字母组成,其他字符作为分割单词的标志),大写全部改成小写,然后排序输出。做法:set排序和去重。stringstream类从一个string对象中读取字符串流(空格为字符串间的分界)。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
string str,buf;
set<string> se;se.clear();
while(cin>>str){
for(size_t i=;i<str.size();++i){
if(isupper(str[i]))str[i]+=;//如果是大写字母,就变成小写字母
if(!isalpha(str[i]))str[i]=' ';//如果不是字母,就变成空格,分割字符串
}
stringstream ss(str);//每次初始化为给定的string对象
while(ss>>buf)se.insert(buf);//读取该字符串中的字符串流
}
for(set<string>::iterator it=se.begin();it!=se.end();++it)
cout<<*it<<endl;
return ;
}

I - Andy's First Dictionary(set+stringstream)的更多相关文章

  1. Andy's First Dictionary(uva 10815) set用法

    参考:https://www.cnblogs.com/yjlblog/p/6947747.html https://blog.csdn.net/hnust_taoshiqian/article/det ...

  2. UVa10615 Andy's First Dictionary(集合set)

    这道题主要用到了set容器和stringstream,用起来非常方便,我第一次见识到,觉得十分的炫酷…… 而且,竟然可以将自己写的单词按照字典序排列,真的太酷了. 下面是书上的代码,目前还处于初学状态 ...

  3. 【UVA - 10815】Andy's First Dictionary (set)

    Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...

  4. LeetCode算法题-Longest Word in Dictionary(Java实现)

    这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...

  5. UVA 10815 Andy&#39;s First Dictionary(字符处理)

    Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...

  6. UVA 10815:Andy's First Dictionary(STL)

    题意:给出一段英文,里面包含一些单词,空格和标点,单词不区分大小写,默认都为小写.按照字典序输出这些单词(这些单词不能有重复,字母全部变成小写) stringstream:包含在头文件#include ...

  7. 安迪的第一个字典(Andy's First Dictionary,Uva 10815)

    输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单 词不区分大小写. 样例输入: Adventures in Disneyland Two blondes were goin ...

  8. set的运用 例题5-3 安迪的第一个字典(Andy's First Dictionary,Uva 10815)

    #include<bits/stdc++.h>using namespace std;set<string> dict;int main(){ string s, buf; w ...

  9. UVA 10815 Andy's First Dictionary (C++ STL map && set )

    原题链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

随机推荐

  1. 【small项目】MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:

    MySQL第二天早上第一次连接超时报错,解决方法com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link ...

  2. hdu -1251 统计难题(字典树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...

  3. hdu - 1172 猜数字 (思维题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1172 这个题换一种想法,可以找出四位数中所有满足条件的数看是否只有一个. #include <iostre ...

  4. codeforces 691D(数据结构)

    D. Swaps in Permutation time limit per test 5 seconds memory limit per test 256 megabytes input stan ...

  5. [bzoj1978][BeiJing2010]取数游戏 game_动态规划_质因数分解

    取数游戏 game bzoj-1978 BeiJing-2010 题目大意:给定一个$n$个数的$a$序列,要求取出$k$个数.假设目前取出的数是$a_j$,那么下次取出的$a_k$必须保证:$j&l ...

  6. java反射-使用反射来操纵方法

    一个类的主要成员时方法,辣么我们通过反射获取到一个类的所有方法信息后,总的寻找一种方式去操作调用这些方法,这样反射才有意义有意思. Method对象有一个方法invoke.      public O ...

  7. URL传递多个参数遇到的bug

    bug所在: 通过URL传递多个参数的时候,其一是中文出现乱码,其二是空格被“%20”替代: 原因分析:原理暂时还不清楚,后续再研究下原理,只知道有中文的时候就会出现乱码:%20是url空格的编码: ...

  8. STL非变易算法

    非变易算法:原则上不会变更操作数据的算法. [1]    for_each:逐个容器元素,原型for_each(InputIter first, InputIter last, Function f) ...

  9. openstack页面自己定义插件使用具体解释(django、ajax、post)(zTree为例)

    感谢朋友支持本博客,欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免,欢迎指正! 如有转载.请保留源作者博客信息. Better Me的博客:blog.csdn.net/tantexian 如需 ...

  10. Appium、selenium与Robot Framework

    Robot Framework + Appium Appium-Python-Client: 与Appium Library和Appium Server的交互Appium Library通过Appii ...