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学长决定好好学习英 ...
随机推荐
- Java中,那些关于String和字符串常量池你不得不知道的东西
老套的笔试题 在一些老套的笔试题中,会要你判断s1==s2为false还是true,s1.equals(s2)为false还是true. String s1 = new String("xy ...
- django模板中导入js、css等静态文件
打开settings.py,在底部添加: import os STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(os.path.dir ...
- jQuery 多选与清除
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 使用amoeba实现mysql读写分离
使用amoeba实现mysql读写分离 1.什么是amoeba? Amoeba(变形虫)项目,专注 分布式数据库 proxy 开发.座落与Client.DB Server(s)之间.对客户端透明. ...
- Mac下IDEA激活Jrebel
第一步:在idea中下载jrebel,过程省略 第二步:配置反向代理工具 Windows 版:http://blog.lanyus.com/archives/317.html MAC 版: 安装hom ...
- redis6.0多线程
https://www.sohu.com/a/331991216_268033 执行还是单线程 读写解析多线程 6.0 https://segmentfault.com/a/1190000 ...
- WPF combobox设置默认选项不生效的问题
combobox 是常用的控件,当我们需要绑定设置默认选项时,往往会绑定 SelectedItem 属性去设置, 可是你会惊奇地发现SelectedItem的值绑定了, 它依旧是熟悉的模样 根据官方的 ...
- UI自动化测试实战
前言 前面我们已经搭建好了wordpress网站,如果需要查看运行效果可以看我前面的搭建文章,下面我们来进行自动化测试的练习. 示例 首先我们测试自动登陆 import unittest from s ...
- Spring听课笔记(专题二)
第3章 Spring Bean的装配(上) 3-1:配置项及作用域 1.Bean的配置项: -- Id -- Class (这个必须,其他的都可以不配置) -- Scope (作用域) -- Cons ...
- Folly解读(零) Fbstring—— 一个完美替代std::string的库
string 常见的三种实现方式 eager copy COW SSO Fbstring 介绍 Storage strategies Implementation highlights Benchma ...