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. UVa 12563_Jin Ge Jin Qu hao

    [题意]在KTV唱歌,假设每首歌最长180s,时间结束时如果还有歌正在唱,则将此歌唱完.为使唱歌时间最长,规定最后唱长达678s的<劲歌金曲>[介是个嘛?] 假设你正在唱KTV,在剩余的t ...

  2. codeforces 691E(矩阵乘法)

    E. Xor-sequences time limit per test 3 seconds memory limit per test 256 megabytes input standard in ...

  3. vue生成包报错error from UglifyJs

    mangle: { keep_fnames: true},

  4. codevs——1039 数的划分

    1039 数的划分 2001年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 将整数 ...

  5. MySQL架构优化实战系列4:SQL优化步骤与常用管理命令

  6. intellij使用tomcat搭建servlet运行时环境

    http://suiyu.online/2017/08/01/intellij%E4%BD%BF%E7%94%A8tomcat%E6%90%AD%E5%BB%BAservlet%E8%BF%90%E8 ...

  7. [52ABP系列] - 001、SPA免费项目模版搭建教程

    前言 这个项目是基于 ABP ASPNetCore 免费版,整合 NG-Alian 和 NG-Zorro 的项目,所以比较适合熟悉 ABP 和 Angular2+ 的开发人员, 如果你是新手,学习的话 ...

  8. CentOS 查看日志命令

    cat tail -f 日 志 文 件 说    明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安 ...

  9. nodejs参考文章

    http://www.cnblogs.com/lily1010/p/6683987.html https://manlili.github.io/2015/04/06/Node%E5%85%A5%E9 ...

  10. 《从零開始学Swift》学习笔记(Day67)——Cocoa Touch设计模式及应用之MVC模式

    原创文章,欢迎转载.转载请注明:关东升的博客   MVC(Model-View-Controller,模型-视图-控制器)模式是相当古老的设计模式之中的一个,它最早出如今Smalltalk语言中. 如 ...