UVA-10815 Andy's First Dictionary (非原创)
10815 - Andy's First Dictionary
Time limit: 3.000 seconds
Problem B: Andy's First Dictionary
Time limit: 3 seconds
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
这题本人用c写的,很繁琐,看博客有一位高手总结的很好,转到这里存一下,博客地址:
http://www.cnblogs.com/zywscq/p/3979958.html
附代码:
1 #include<iostream>
2 #include<cstdio>
3 #include<cstdlib>
4 #include<cstring>
5 #include<cmath>
6 #include<map>
7 #include<set>
8 #include<vector>
9 #include<algorithm>
10 #include<stack>
11 #include<queue>
12 #include<cctype>
13 #include<sstream>
14 using namespace std;
15 #define INF 1000000000
16 #define eps 1e-8
17 #define pii pair<int,int>
18 #define LL long long int
19 #define maxn 100009
20 string s,buf;
21 set<string>dict;
22 int main()
23 {
24 //freopen("in.txt","r",stdin);
25 //freopen("out.txt","w",stdout);
26 while(cin>>s)
27 {
28 int len=s.length();
29 stringstream ss;
30 for(int i=0;i<len;i++)
31 {
32 if(isalpha(s[i])) s[i]=tolower(s[i]);
33 else s[i]=' ';
34 }
35 ss<<s;
36 /*也可以ss.str(s),如果清空ss的内容就用ss.str("")。注意ss.str(s)是覆盖掉ss中原来的东西,而ss<<s是在后面添加上s*/
37 while(ss>>buf)//空格都不会传
38 {
39 dict.insert(buf);
40 }
41 }
42 for(set<string>::iterator it=dict.begin();it!=dict.end();it++)
43 //注意不能写成it<dict.end(),只有等与不等
44 cout<<*it<<endl;
45 return 0;
46 }
UVA-10815 Andy's First Dictionary (非原创)的更多相关文章
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- 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 ...
- Uva 10815 Andy's First Dictionary(字符串)
题目链接:https://vjudge.net/problem/UVA-10815 题意 找出一段文本中的所有单词,以小写形式按照字典序输出. 思路 用空白符替换文本中所有非字母字符后再次读入. 代码 ...
- UVA 10815 Andy's First Dictionary (C++ STL map && set )
原题链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- UVA 10815 Andy's First Dictionary ---set
题目链接 题意:输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单词不区分大小写. 刘汝佳算法竞赛入门经典(第二版)P112 #include <iostream> ...
- UVA 10815 Andy's First Dictionary【set】
题目链接:https://vjudge.net/contest/211547#problem/C 题目大意: 输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写 ...
- 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 ...
- 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 (set)
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英 ...
随机推荐
- SAP FTP FOR ABAP programing
近来忙的不可开交,忙的一塌糊涂,呵呵,今天怀揣愧疚之心,上来分享博文一篇,算是对自己的一点安慰. 首先在SAP系统中提供了很多的FTP示例程序,如下: RSFTP001 SAPFT ...
- 好你个C语言,原来还有这么多副面孔!
C语言可以这样比喻,是一门非常强大的内功心法,学会它可以做到一法通万法.这也是它至今不衰的原因.说了这么多C语言的优点,现在来说说它的缺点.C语言最大的优点也是它最大的缺点,拥有强大的力量时应时刻保持 ...
- pytest学习笔记(pytest框架结构)
一.pytest框架中使用setup.teardown.更灵活按照用例级别可以分为以下几类: 1.模块级:(setup_module.teardown_module)在模块始末调用 2.函数级:(se ...
- MySQL简介及安装 mysql Ver 14.14 Distrib 5.7.28
1.MySQL简介 1.数据库产品演变 第一代数据库架构: RDBMS 关系型数据库时代 : 合的时代 代表产品 :Oracle .MSSQL .MySQL.SQL server 第二代数据库架构:拆 ...
- 06. struts2中指定struts2处理的请求后缀
概述 默认情况下我们都是使用.action后缀访问Action. 其实默认后缀是可以通过常量"struts.action.extension"进行修改的. 我们可以配置Struts ...
- Spring Security,没有看起来那么复杂(附源码)
权限管理是每个项目必备的功能,只是各自要求的复杂程度不同,简单的项目可能一个 Filter 或 Interceptor 就解决了,复杂一点的就可能会引入安全框架,如 Shiro, Spring Sec ...
- Failed to start ssh.service: Unit not found.
Failed to start ssh.service: Unit not found. 报错内容: [Centos7@localhost ~]$ service ssh start Redirect ...
- OpenSSL 常见对称加密算法特性分析
在选择加密算法,面对一大长串的选项时,大家都有这样的疑问,究竟哪种加密方式是最好的呢? 对于加密方式.算法来说,一般安全性与性能呈负相关,越是安全的,对性能要求则更高. 现在主流的加密协议的安全性均能 ...
- 在Ubuntu下安装Jenkins
一.安装Jenkins 1. 确保Java环境已经安装配置好 java -version 2. 将存储库密钥添加到系统 wget -q -O - https://pkg.jenkins.io/debi ...
- Spring Boot 两种多数据源配置:JdbcTemplate、Spring-data-jpa
多数据源配置 JdbcTemplate支持 Spring-data-jpa支持 多数据源配置 创建一个Spring配置类,定义两个DataSource用来读取application.propertie ...