STL之set_uva10815

原创 2016年04月15日 23:07:53

Problem B: Andy's First Dictionary

Time limit: 3 seconds


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


/*
* Filename:    code.cpp
* Created:     2016-04-15
* Author:        yunlong Wang  
*[mail:17744454343@163.com]
* Desciption:  Desciption
*/
<span style="font-size:18px;">#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <list>
#include <sstream>
#include <set>
#include <functional>

using namespace std;

#define INT_MAX 1 << 30
#define MAX 100

typedef long long ll;

int n;
set<string>dic;

int main(int argc, char const* argv[])
{
    string s,every;
    while (cin >> s)                            //用string和用char数组时操作要格外区分
    {
        for (int i = 0; i < s.length(); i += 1)
        {
            if (isalpha(s[i]))                  //判断是否为英文字母。。。
            {
                s[i] = tolower(s[i]);           //变为小写
            }
            else
            {
                s[i] = ' ';
            }
        }
        stringstream ss(s);                     //创建一个字符串流
        while (ss >> every)                     //读取每个字符串并放入set中
        {
            dic.insert(every);                  //set有自动排序这一功能
        }
    }
    for (set<string>::iterator i = dic.begin(); i != dic.end(); i++)    //set<string>::iterator为引用,相当于指针.
    {
        cout << *i << endl;
    }
    return 0;
}</span>


版权声明:欢迎大家指出文中的错误和不足之处

相关文章推荐

UVa-10815-Andy's First Dictionary c++ STL set 基础练习题

题意:输入一个文本,找出所有不同的单词,按字典序排列输出,不区分大小写                 本题主要是让我们练习STL set容器的使用和了解其特点         set 容器具...

容器set与字符操作:UVA - 10815

关键函数: isalpha(ch)//返回字符ch是否为字母 tolower(ch)//返回字符ch小写形式的ASCII码 getline(cin,str)//读入一行字符串到字符串变量str...
  • DMW2016
  • DMW2016
  • 2017年02月09日 21:34
  • 63

UVA10815-5.3-Andy's First Dictionary(集合set的用法)

UVA10815-5.3-Andy’s First Dictionary(集合set的用法) 题目描述: 链接: https://uva.onlinejudge.org/index.php?op...

uva 10815 Andy's First Dictionary stl 函数

Andy's First Dictionary DESCRIPTION Andy, 8, has a dream - he wants to produce his very own ...

UVA 10815Andy's First Dictionary【set使用+set排序】好方便啊!

Andy's First Dictionary Andy, 8, has a dream - he wants to produce his very own dictionary. This ...

UVA12096,STL stack和set,Map的综合运用

&emsp;紫书的STL介绍,比较抽象,教我们怎么表示一些抽象的集合并进行一些简单的操作,其中Set_Set_ID和vector Set_Set;是关键,然后关于set_union,set_inter...
  • gyh_420
  • gyh_420
  • 2017年04月08日 23:03
  • 87

UVa 496 Simply Subsets (STL&set_intersection)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&p...

UVA 156 Ananagrams(stl,map,set)

例题4:UVA 156 Ananagrams 题目:把每个单词全部转化成小写字母,对每个单词,看它的字母重排后得到的单词在所有输入的单词中是否出现过,若没有出现,就输出原单词。所有要输出的单词按字典...

字符串训练 ----- UVA 10815题目Andy's First Dictionary

解题思路: 本题主要是涉及分割获取单词  然后按字典排序输出单词 (这个只要用qsort排序下就好了) AC代码如下 #include #include #include u...
  • WU5151
  • WU5151
  • 2015年07月28日 10:04
  • 368

Uva 10815 Andy's First Dictionary (字典序)

Andy's First DictionaryTime Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu Submi...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:STL之set_uva10815
举报原因:
原因补充:

(最多只允许输入30个字)