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
构造一个不反复的字典。

map一下就可以。

(大写和小写)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
typedef long long LL;
using namespace std;
#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )
#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )
#define CLEAR( a , x ) memset ( a , x , sizeof a )
map<string,int>p;
struct node{
char s[1100];
}e[5500*200];
int cmp(node l1,node l2)
{
return strcmp(l1.s,l2.s)<0;
}
int main()
{
std::ios::sync_with_stdio(false);
char str[100];
int l=0;
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
// cout<<"2333 "<<str<<endl;
REP(i,len)
{
int j;
if(isalpha(str[i]))
{
char s1[1100];
int ll=0;
for(j=i;j<len;j++)
{
if(isalpha(str[j])) s1[ll++]=tolower(str[j]);
else break;
}
s1[ll]='\0';
if(!p[s1]) { p[s1]=1; strcpy(e[l++].s,s1);}
i=j-1;
}
}
}
sort(e,e+l,cmp);
REP(i,l) cout<<e[i].s<<endl;
return 0;
}

UVA 10815 Andy&#39;s First Dictionary(字符处理)的更多相关文章

  1. UVa 10815 Andy's First Dictionary

    感觉这道题要比之前几个字符串处理的题目难度要大了一些. 题目大意:给若干行字符串,提取出所有单词并去掉重复的,最后按字典顺序输出. 对于输入大致有两种思路,一种是逐个读入字符,遇到字母的话就放到wor ...

  2. 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 ...

  3. Uva 10815 Andy's First Dictionary(字符串)

    题目链接:https://vjudge.net/problem/UVA-10815 题意 找出一段文本中的所有单词,以小写形式按照字典序输出. 思路 用空白符替换文本中所有非字母字符后再次读入. 代码 ...

  4. UVA 10815 Andy's First Dictionary (C++ STL map && set )

    原题链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...

  5. UVA 10815 Andy's First Dictionary ---set

    题目链接 题意:输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出.单词不区分大小写. 刘汝佳算法竞赛入门经典(第二版)P112 #include <iostream> ...

  6. UVA 10815 Andy's First Dictionary【set】

    题目链接:https://vjudge.net/contest/211547#problem/C 题目大意: 输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写 ...

  7. Andy&#39;s First Dictionary

    Description Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy ...

  8. 安迪的第一个字典(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 ...

  9. 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 ...

随机推荐

  1. JDK和JRE的差异和区别

    来源:http://docs.oracle.com/javase/7/docs/

  2. Dapper 基础用法

    Dapper是.Net下的一个简单orm框架,具有以下特点: 1.简单,只需要一个文件即可(SqlMapper.cs) 2.快速,下面是一个查询结果集在500以上的运行速度对比 3.不要求特定的db ...

  3. java读写

    IO流下分为字节流与字符流,每个流又分为输入输出以及读写. 字节流的两个基类为InputStream与OutputStream. 字符流为Reader和Writer

  4. Week13(12月5日):不怕错误,慢慢来 :)

    Part I:提问 =========================== 1.ASP.NET MVC的最新版本是(      ). A.2    B.3    C.4   D.5 2.本学期授课中使 ...

  5. Qt在windows 平台操作保存execel的表格(通过QAxObject来操作)

    粗略操作 QT += core gui sql CONFIG += qaxcontainer greaterThan(QT_MAJOR_VERSION, 4): QT += widgets #incl ...

  6. vim Ctags 和taglist安装和使用

    Ctags是一个用于从程序源代码树产生索引文件(或tag文件),从而便于文本编辑器来实现快速定位的实用工具.在产生的tag文件中,每一个tag的入口指向了一个编程语言的对象.这个对象可以是变量定义.函 ...

  7. 「操作系统」: Conditional Move Instructions(trap)

    Not all conditional expressions can be compiled using conditional moves. Most significantly, the abs ...

  8. cocos2d-x游戏开发系列教程-超级玛丽07-CMGameMap(四)-马里奥平移

    上一篇博文提到,程序如何获取键盘输入,也就是D键按下,程序获取到前进指令,那么获取到前进指令之后,马里奥是如何前进的呢,这篇文章我们重点讨论这个问题. 马里奥的移动,依旧是在帧刷新函数中,这个调用过程 ...

  9. cmake 学习笔记(二)

    在 Cmake学习笔记一 中通过一串小例子简单学习了cmake 的使用方式. 这次应该简单看看语法和常用的命令了. 简单的语法 注释 # 我是注释 命令语法 COMMAND(参数1 参数2 ...) ...

  10. &lt;深入理解C指针&gt;学习笔记和总结 第四章 指针和数组

    数组是一个什么玩意: 数组和指针我的理解,有同样之处也有不同之处.因有同样之处,因此一些资料上说,数组和指针本质是同样的.因有不同之处,因此也有一些资料上说,数组和指针是不一样的. 同样之处: 数组名 ...