Andy‘s First Dictionary UVA - 10815
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
HINT
这个题就是让自己来学会是使用set容器的,解释都是注释里面
Accepted
#include<algorithm>
#include <iostream>
#include<sstream>
#include<set>
#include<string>
using namespace std;
set<string>dict;
int main()
{
string s, buf; //存储每一个单词
while (cin >> s)
{
for (int i = 0;i < s.length();i++)
if (isalpha(s[i]))s[i] = towlower(s[i]); //判断是否是字母并将字母小写形式重新赋给自己
else s[i] = ' '; //标点符号变为空格
stringstream ss(s); //将s赋给ss;
while (ss >> buf) //将ss一个单词一个单词的赋给buf
dict.insert(buf); //将单词插入到set容器里面,set容器会自动排序从小到大
}
for (set<string>::iterator it = dict.begin();it != dict.end();++it) //.begin()返回的是一个迭代器类型,类似于指针
cout << *it << endl; //输出单词
return 0;
}
Andy‘s First Dictionary UVA - 10815的更多相关文章
- 安迪的第一个字典(Andy's First Dictionary,UVa 10815)
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...
- STL语法——集合:set 安迪的第一个字典(Andy's First Dictionary,UVa 10815)
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- 【UVA - 10815】Andy's First Dictionary (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- UVa10815.Andy's First Dictionary
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA-10815 Andy's First Dictionary (非原创)
10815 - Andy's First Dictionary Time limit: 3.000 seconds Problem B: Andy's First DictionaryTime lim ...
- Problem C: Andy's First Dictionary
Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...
- 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
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...
随机推荐
- PriorityQueue使用介绍
这玩意儿叫优先级队列,是一个类,继承了AbstractQueue类,实现了Serializable接口. jdk文档里是这么描述这玩意的: 基于优先级堆的无限优先级queue . 优先级队列的元素根据 ...
- 痞子衡嵌入式:串行NOR Flash的DQS信号功能简介
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是串行NOR Flash的DQS信号功能. 串行NOR Flash在嵌入式里的应用相当广泛,既可用作数据存储也可以用作代码(XiP)存储, ...
- Linux安装ElasticSearch7.X & IK分词器
前言 安装ES之前,请先检查JDK版本,es使用java编写,强依赖java环境.JDK安装过程略. 安装步骤 1.下载地址 点击这里下载7.2.0 2.解压elasticsearch-7.2.0-l ...
- 微信小程序使用彩色图标(阿里巴巴 iconfont Symbol 的用法)微信小程序使用彩色图标(阿里巴巴 iconfont Symbol 的用法)
前提 需要安装好 nodejs (略) 用于下载插件 安装插件 npm install mini-program-iconfont-cli --save-dev 初始化配置文件 npx iconfon ...
- 【图像处理】使用OpenCV进行图像处理教程(一)
OpenCV是进行图像处理的工具,也是计算机视觉领域近十几年不断发展和完善的产物.面对这个已基本成熟的开源库知识体系,我们新生代有必要不断地总结.回顾,以新的视角快速融入计算机视觉的奥秘世界. 从这篇 ...
- 话说 synchronized
一.前言 说起java的锁呀,我们先想到的肯定是synchronized[ˈsɪŋ krə naɪ zd]了 ,这个单词很拗口,会读这个单词在以后的面试中很加分(我面试过一些人 不会读 ,他们说的 ...
- AJAX基本操作
XMLHttpRequest对象: XMLHttpRequest 是 AJAX 的基础.所有现代浏览器均支持 XMLHttpRequest 对象(IE5 和 IE6 使用 ActiveXObject) ...
- PAT-1150(Travelling Salesman Problem)旅行商问题简化+模拟图+简单回路判断
Travelling Salesman Problem PAT-1150 #include<iostream> #include<cstring> #include<st ...
- const修饰符相关
const修饰符相关 const修饰符表明一个变量是常量,大致分为三类:常量数组(等同于常量指针),常量指针,指向常量的指针. 常量数组中数据都是不可修改的,任何试图修改常量数组中的数据的操作都会报错 ...
- Linux速通02 命令格式
命令的格式 # 格式:命令 [选项][参数] * 命令:告诉 Linux操作系统执行什么 * 选项:说明命令运行的方式(可以改变命令的功能).以 "-"字符开始 * 参数:说明命令 ...