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学长决定好好学习英 ...
随机推荐
- 回溯算法——解决n皇后问题
所谓回溯(backtracking)是通过系统地搜索求解问题的方法.这种方法适用于类似于八皇后这样的问题:求得问题的一个解比较困难,但是检查一个棋局是否构成解很容易. 不多说,放上n皇后的回溯问题代码 ...
- 微服务深入浅出(9)-- Nginx
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,处理请求是异步非阻塞的,多个连接(万级别)可以对应一个进程.而Apache是同步多进程模型,一个连接对 ...
- zzd 的割草机(Lawnmower)
评测传送门 [题目描述] 已知花坛为一个 n * m 的矩形,草只会长在某些个格子上,zzd 有一个割草机,一开始,zzd 站在(1,1)处,面向(1,m)(面向右).每次 zzd 有两个选择(耗费一 ...
- Python练习-函数版-锁定三次登陆失败的用户
代码如下: # 编辑者:闫龙 if __name__ == '__main__': import UserLoginFuncation LoclCount=[]; while True: UserNa ...
- perl6 Net::HTTP 不能发送https请求
如下命安装必要的包: sudo apt install libssl1.0.0 libssl-dev zef install IO::Socket::SSL zef install Net::HTTP
- Linux Kernel sys_call_table、Kernel Symbols Export Table Generation Principle、Difference Between System Calls Entrance In 32bit、64bit Linux【转】
转自:http://www.cnblogs.com/LittleHann/p/4127096.html 目录 1. sys_call_table:系统调用表 2. 内核符号导出表:Kernel-Sym ...
- Vim 快捷键整理【转】
转自:http://blog.csdn.net/ceven2010/article/details/7406341 一.移动光标 1.左移h.右移l.下移j.上移k 2.向下翻页ctrl + f,向上 ...
- a标签、img图片、iframe、表单元素、div
1.<a href="http://www.baidu.com" target=''_blank">百度</a> 超链接标签 2.<img ...
- 30 C? Go? Cgo!
C? Go? Cgo! 17 March 2011 Introduction Cgo lets Go packages call C code. Given a Go source file writ ...
- vue总结07 常用插件
插件 开发插件 插件通常会为 Vue 添加全局功能.插件的范围没有限制——一般有下面几种: 添加全局方法或者属性,如: vue-custom-element 添加全局资源:指令/过滤器/过渡等,如 v ...