I - Andy's First Dictionary(set+stringstream)
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)的更多相关文章
- Andy's First Dictionary(uva 10815) set用法
参考:https://www.cnblogs.com/yjlblog/p/6947747.html https://blog.csdn.net/hnust_taoshiqian/article/det ...
- UVa10615 Andy's First Dictionary(集合set)
这道题主要用到了set容器和stringstream,用起来非常方便,我第一次见识到,觉得十分的炫酷…… 而且,竟然可以将自己写的单词按照字典序排列,真的太酷了. 下面是书上的代码,目前还处于初学状态 ...
- 【UVA - 10815】Andy's First Dictionary (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- LeetCode算法题-Longest Word in Dictionary(Java实现)
这是悦乐书的第303次更新,第322篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第171题(顺位题号是720).给出表示英语词典的字符串单词数组,找到单词中长度最长的单 ...
- UVA 10815 Andy's First Dictionary(字符处理)
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...
- UVA 10815:Andy's First Dictionary(STL)
题意:给出一段英文,里面包含一些单词,空格和标点,单词不区分大小写,默认都为小写.按照字典序输出这些单词(这些单词不能有重复,字母全部变成小写) stringstream:包含在头文件#include ...
- 安迪的第一个字典(Andy's First Dictionary,Uva 10815)
输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单 词不区分大小写. 样例输入: Adventures in Disneyland Two blondes were goin ...
- 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 ...
- UVA 10815 Andy's First Dictionary (C++ STL map && set )
原题链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
随机推荐
- JPA中映射关系详细说明(一对多,多对一,一对一、多对多)、@JoinColumn、mappedBy说明
JPA中的映射关系 jpa中维护one to one ,one to many, many to one ,many to many 四种映射关系. 在每个关系中,双方中的一方在其表中拥有连接列.那么 ...
- Codeforces908G. New Year and Original Order
给n<=10^700,问1到n中每个数在各数位排序后得到的数的和.答案膜1e9+7. 一看就是数位DP啦..然而并没有什么思路.. 可以尝试统计n(i,j)表示数j在第i位的出现次数,知道了这个 ...
- Linux下C编程入门(1)
Linux系统的介绍(以下以Manjaro最新版为例子): 一.系统的安装: 1.可以直接使用U盘做一个live usb的启动盘,在bios中设置从U盘启动即可拥有linux系统,如果是新式bios需 ...
- Linux下汇编语言学习笔记6 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- 用jQuery向div中添加Html文本内容
前台代码: <link href="http://www.cnblogs.com/Content/themes/base/jquery-ui.css" rel="s ...
- [bzo1211][HNOI2004]树的计数_prufer序列
树的计数 bzoj-1211 HNOI-2004 题目大意:题目链接. 注释:略. 想法: prufer序列有一个性质就是一个数在prufer序列中出现的次数等于这个prufer序列生成的树中它的度数 ...
- sqlalchemy多表联合查询的左连接、右连接等使用
#按用户名摸糊查询trans_details.query.join(Uses).filter(Users.username.like('%xx%'))#select xxx from trans_de ...
- laravel event
事件监听 方法一: web.php Event::listen('eloquent.created: App\post',function(){ dump('A post was created'); ...
- js程序基础字符串具体
1. .charAt()里面写数字 在一般浏览器上相当于方括号 可是由于IE6的存在他就有了用处 由于IE6不兼容方括号 2. charCodeAt() 和charAt几乎相 ...
- activiti自己定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
注:(1)环境搭建:activiti自己定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建 (2)创建流程模型:activiti自己定义流程之Spr ...