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. NSUserDefaults概述

    原创,转载请注明原文:NSUserDefaults概述  By Lucio.Yang 首先,iOS中有四种存储数据的方式-对比iOS中的四种数据存储 NSUserDefaults是其中很常用的一种.N ...

  2. bootstrap基础知识

    Bootstrap是Twitter推出的一款简洁.直观.强悍的前端开发框架. Bootstrap基于 HTML.CSS.JAVASCRIPT.它由Twitter的设计师Mark Otto和Jacob ...

  3. Android EditText 无法换行

    问题 关于控制是否换行的属性android:singleLine 当值为true的时候,只能一行,不换行 当值为false的时候,可以换行 但是现在遇到一个问题: <EditText andro ...

  4. cocos2dx进阶学习之CCSpriteBatchNode

    继承关系 CCSpriteBatchNode -> CCNode, CCTextureProtocol 成员变量 inline CCTextureAtlas* getTextureAtlas(v ...

  5. android面试题之三

    十一.对一些资源以及状态的操作保存,最好是保存在生命周期的哪个函数中进行? 若在onPause()中进行保存,相应需要在onResume()中进行恢复. 若在onStop()中进行保存,相应需要在on ...

  6. ThinkPHP - 自动创建 + 自动验证 + 自动完成

    自动创建:创建数据模型. $User->create(); 自动验证:验证提交的表单数据. protected $_validate = array( array('verify','requi ...

  7. 【Android】ScrollView+GridView 显示问题

    在使用Android的ScrollView里面嵌套GridView时,设置android:layout_height="wrap_content"属性,运行界面的效果不会出现全部数 ...

  8. 修改字符串 ToCharArray()

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. [Swust OJ 85]--单向公路(BFS)

    题目链接:http://acm.swust.edu.cn/problem/0085/ Time limit(ms): 5000 Memory limit(kb): 65535   Descriptio ...

  10. django-extensions

    命令行: admin后台管理扩展 后面会出现个放大镜实现搜索补齐功能. 交互式的 Python Shells(shell_plus) 实现自动导入 如果遇到apps中包含的的models名字出现冲突, ...