set的应用:UVa10815-Andy's First Dictionary
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, 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的应用,题意是给你一篇文章,让你输出里面有多少个不同的单词,主要是处理一下里面的标点符号,然后裸的set就可以过了。
- 里面的用了三个库函数,isalpha(char)如果是字母返回true,不然返回false。tolower(char)把一个字母转换成小写字母。stringstream ss(string)将一个string类型输入到ss之中。有点像c中的sprintf;
#include<bits/stdc++.h>
using namespace std;
set <string> se;
string s;
int main()
{
while(cin>>s)
{
string::iterator iter1;
string s1;
for(iter1=s.begin();iter1!=s.end();iter1++)
{
if(isalpha(*iter1))
*iter1 = tolower(*iter1);
else
*iter1 = ' ';
}
stringstream ss(s);//这里要转换一下,如果标点符号在中间可能形成两个单词
while(ss >> s1)
se.insert(s1);
s.clear();
}
set <string> :: iterator iter;
for(iter=se.begin();iter!=se.end();iter++)
cout<<*iter<<endl;
return 0;
}
set的应用:UVa10815-Andy's First Dictionary的更多相关文章
- 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 ...
- 【UVA - 10815】Andy's First Dictionary (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- Problem C: Andy's First Dictionary
Problem C: Andy’s First DictionaryTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 18 Solved: 5[Submit] ...
- 安迪的第一个字典 (Andy's First Dictionary,UVa10815)
题目描述: #include<iostream> #include<string> #include<set> #include<sstream> us ...
- Andy's First Dictionary
Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...
- 安迪的第一个字典(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 STL
Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him ...
随机推荐
- Hive_Hive体系结构
元数据: HQL的执行过程 ORACEL 执行计划,Hive 类似. 无索引时,生成全表扫描执行计划,执行全表扫描. 创建索引后,重新生成SQL语句执行计划,基于索引扫描,提高查询效率.
- 简单了解junit的使用
普通使用: 在没有用测试框架之前,我们要用一个main方法来跑代码,而有了像junit这样的测试框架后,就可以不用次次写个main方法了. 直接上代码,注释里有说明: package com.stuP ...
- 543 Diameter of Binary Tree 二叉树的直径
给定一棵二叉树,你需要计算它的直径长度.一棵二叉树的直径长度是任意两个结点路径长度中的最大值.这条路径可能穿过根结点.示例 :给定二叉树 1 / \ 2 ...
- 096 Unique Binary Search Trees 不同的二叉查找树
给出 n,问由 1...n 为节点组成的不同的二叉查找树有多少种?例如,给出 n = 3,则有 5 种不同形态的二叉查找树: 1 3 3 2 1 ...
- select的type属性
select的type属性经常被我们所忽视,今天在看JQ的val钩子的时候,看到了这么一句话: one = elem.type === "select-one" || index ...
- SSAS 维度属性自定义排序
默认设置: 排序设置:
- WPF 控件树
WPF控件树按照基类进行分类,记录下来便于编写自定义控件时查阅 RangeBase范围控件 Thumb拖到控件 TextBoxBase文本控件 ItemControl组控件 ContrentContr ...
- 两小时学Thinkphp3.1(多数来自thinkphp3.1快速入门)
调试模式 define('APP_DEBUG',TRUE); 定义自动验证 protected $_validate = array( array('title','require','标题必须'), ...
- COGS 2211. [BZOJ3653]谈笑风生
★★★★ 输入文件:laugh.in 输出文件:laugh.out 简单对比时间限制:3 s 内存限制:512 MB [问题描述] 设T 为一棵有根树,我们做如下的定义: • 设a和b ...
- 洛谷 P3183 [HAOI2016]食物链
题目描述 如图所示为某生态系统的食物网示意图,据图回答第1小题现在给你n个物种和m条能量流动关系,求其中的食物链条数.物种的名称为从1到n编号M条能量流动关系形如a1 b1a2 b2a3 b3.... ...