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, 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
题意:将文章中所有单词转换成小写,并按字典序排序
解法:可使用STL的vector容器,储存每个单词,然后使用sort函数,将vector中的每个单词按照字典序排,最后输出
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<ctype.h>
#include<vector>
using namespace std;
char c,s[10010];
vector<string> vec;
int main()
{ int i,m=0;
while(~(c=getchar()))
{ if(isupper(c)||islower(c)) //可使用isalpha 小写为2 大写为1
s[m++]=tolower(c);
else if(m!=0)
{ s[m]='\0';
vec.push_back(s); //在尾部加入字符串
m=0;
}
}
sort(vec.begin(),vec.end());
for(i=0;i<vec.size();i++)
if(i==0 || vec[i]!=vec[i-1] )
cout<<vec[i]<<endl;
}
UVA - 10815 - Andy's First Dictionary STL的更多相关文章
- UVa 10815 Andy's First Dictionary
感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...
- 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(字符串)
题目链接:https://vjudge.net/problem/UVA-10815 题意 找出一段文本中的所有单词,以小写形式按照字典序输出. 思路 用空白符替换文本中所有非字母字符后再次读入. 代码 ...
- 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 (非原创)
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学长决定好好学习英 ...
随机推荐
- Lucene之Java实战
1.导包 2.索引的创建 2.1首先,我们需要定义一个词法分析器. Analyzer analyzer = new IKAnalyzer();//官方推荐 Analyzer analyzer = ne ...
- 20155225 2016-2017-2 《Java程序设计》第七周学习总结
20155225 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 java提供的时间处理API 认识时间与日期,时间日期处理不是我想象中那么简单的问题,涉及地 ...
- Dynamic Rankings(动态第k大+树套树)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1112 题目: 思路: 树套树板子题. 代码实现如下: #inclu ...
- Java编程思想 4th 第3章 操作符
有了数据,还需要进行数据间的运算,因此Java中也有数据间运算的各种符号,书本称之为操作符,正确的翻译应该是运算符. Java中的运算符同C++相同,运算符同运算符对象构成表达式,表达式是运算对象及运 ...
- 20165227 学习基础和C语言基础调查
学习基础和C语言基础调查 技能学习经验和感悟 你有什么技能比大多人(超过90%以上)更好? 如果非要说出来一个的话,那就是篮球了.从热爱篮球,到热爱打篮球,经历挫折阻碍,不断反思学习,一步一步地向前迈 ...
- 20165230 《Java程序设计》实验二(Java面向对象程序设计)实验报告
20165230 <Java程序设计>实验二(Java面向对象程序设计)实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩: ...
- C 之回调函数
软件模块之间总是存在着一定的接口,从调用方式上,可以把他们分为三类:同步调用.回调和异步调用.同步调用是一种阻塞式调用,调用方要等待对方执行完毕才返回,它是一种单向调用:回调是一种双向调用模式,也就是 ...
- python网络编程-socket上传下载文件(包括md5验证,大数据发送,粘包处理)
ftp server 1) 读取文件名 2)检查文件是否存在 3)打开文件 4)检查文件大小 5)发送文件大小给客户端 6)等客户端确认 7)开始边读边(md5计算)发数据 8)给客户端发md5 ft ...
- Python 深拷贝、浅拷贝
Python中,对象的赋值,拷贝(深/浅拷贝)之间是有差异的,如果使用的时候不注意,就可能产生意外的结果. 首先,对赋值操作我们要有以下认识: 赋值是将一个对象的地址赋值给一个变量,让变量指向该地址( ...
- java 内部类与控制框架
应用程序控制框架(application framework)就是设计解决某类特殊问题的一个类,或一组类,要运用某个应用程序框架,通常是继承一个类或多个类,并覆盖这些方法.在覆盖的方法中编写代码定制应 ...