UVa 10815 Andy's First Dictionary:分离字符串

10815 - Andy's First Dictionary

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=1756

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实现:(set实现)

/*0.029s*/

#include<cstdio>
#include<string>
#include<set>
using namespace std;  

set<string>s;
set<string>::iterator it;
string str;  

int main(void)
{
    char ch;
    while (~(ch = getchar()))
    {
        if (!isalpha(ch))
        {
            if (str != "")
                s.insert(str);
            str = "";
        }
        else
            str += tolower(ch);
    }
    for (it = s.begin() ; it != s.end() ; ++it)
        puts((*it).c_str());
    return 0;
}

非STL实现:(但是会RE,不知道为什么)

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;  

char word[5010][210], *p[5010], ch;  

inline bool getword(char *s)
{
    while (!isalpha(ch = getchar()))
        if (ch == -1) return false;
    int i = 0;
    s[i++] = tolower(ch);
    while (isalpha(ch = getchar()))
        s[i++] = tolower(ch);
    s[i] = '\0';
    return true;
}  

bool cmp(char *a, char *b)
{
    return strcmp(a, b) < 0;
}  

int main(void)
{
    int n;
    for (n = 0; getword(word[n]); ++n)
        p[n] = word[n];
    sort(p, p + n, cmp);
    if (n) puts(p[0]);
    for (int i = 1; i < n; ++i)
        if (strcmp(p[i], p[i - 1]))
            puts(p[i]);
    return 0;
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索include
, return
, uva 10815
, char
, p has no constructo
, words
, in
, The
isalpha
uva 10815、uva lou s list、andy ridings、andy murray s coach、uvaoj10815,以便于您获取更多的相关知识。

时间: 2024-11-03 10:08:28

UVa 10815 Andy's First Dictionary:分离字符串的相关文章

uva 10815-UVa-10815 Andy&amp;amp;#39;s First Dictionary

问题描述 UVa-10815 Andy's First Dictionary 题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18649 以下是我的java代码: package UVaOJ; import java.util.Scanner; import java.util.TreeSet; public class Main { public static String filter(String s){ S

急啊!!!分离字符串表示的算术表达式的数字与运算符

问题描述 有字符串表示的算术表达式,比如:12.3+21*2-34.6,我现在想把这个表示中的数字与运算符分离,并计算出结果,该怎么分离啊?我想用正则表达式来做,但是总分离不出来,看看那位高手能指点一下啊! 解决方案 解决方案二:告诉楼主个思路,先用正则表达式分离然后放入两个队列,一个数字,一个符号,que1{21,2,×,12.3,+,34.6,-}快断网了....+优先级<后面个,放入队列,×>-前后放入队列,-=+,放入+和它前面那个,每次比较最近的两个运算符,相等就放前面的,不然放优先

刘汝佳uva 字符串专题

第一题   palindrome 点击打开链接uva 401 题目意思:给定一个字符串判断是什么类型 分析: 1 根据输出我们知道这个字符串总共有4种类型 2 首先应该是否是"palindrome ",判断的理由很简单直接对这个字符串进行判断,但是这里有个地方会出错就是'0'和'O',题目明确说明了'0'和'O'看成相同,所以我们应该在输入的时候就把所有的'0'处理成'O',注意这里不能把'O'改成'0'(想想为什么?) 3 接下来判断是否是"mirrored string&

UVa 10887:Concatenation of Languages

链接: UVa :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1828 类型:  哈希表 原题: A language is a set of strings. And the concatenation of two languages is the set of all strings that a

uva 10688:The Poor Giant(区间dp)

题目链接: uva-10688 http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=514&page=show_problem&problem=1629 题意 有n个苹果,和一个数k,第i个苹果的重量是k+i(1<=i<=n). 已知其中只有一个苹果是甜的, 所有比它重量轻的都是苦的,比它重的都是酸的. 为了要找出甜的苹果,就要去一个一个地吃它,且吃了咬了苹果

UVa 529:Addition Chains ,迭代加深搜索+减枝

题目链接: UVA :http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=470 POJ : http://poj.org/problem?id=2248 类型: 回溯, 迭代加深搜索, 减枝 原题: An addition chain for n is an integer sequence with the f

UVa 10125:Sumsets

题目链接: UVa : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1066 poj :   http://poj.org/problem?id=2549 类型: 哈希, 二分查找 原题: Given S, a set of integers, find the largest d such that a

php中利用explode函数分割字符串到数组

 这篇文章主要介绍了php中利用explode函数分割字符串到数组,需要的朋友可以参考下 分割字符串    //利用 explode 函数分割字符串到数组  代码如下: <?php  $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串  $hello = explode(',',$source);    for($index=0;$index<count($hello);$index++)  {  echo $

.NET中删除空白字符串的10大方法

我们有无数方法可用于删除字符串中的所有空白,但是哪个更快呢? 介绍 我们有无数方法可用于删除字符串中的所有空白.大部分都能够在绝大多数的用例中很好工作,但在某些对时间敏感的应用程序中,是否采用最快的方法可能就会造成天壤之别. 如果你问空白是什么,那说起来还真是有些乱.许多人认为空白就是SPACE 字符(UnicodeU+0020,ASCII 32,HTML ),但它实际上还包括使得版式水平和垂直出现空格的所有字符.事实上,这是一整类定义为Unicode字符数据库的字符. 本文所说的空白,不但指的