STL之set_uva10815


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>


阅读更多
版权声明:欢迎指出文中的错误和不足之处 https://blog.csdn.net/xxiaobaib/article/details/51165436
文章标签: set uva 10815
个人分类: stl
想对作者说点什么? 我来说一句

stl的学习:c++ STL

2009年09月07日 537KB 下载

走进STL走进STL走进STL

2011年06月04日 68KB 下载

stl源码剖析 stl源码剖析

2010年08月05日 7.03MB 下载

STL 例题.RAR

2011年07月21日 1.32MB 下载

STL源码剖析

2008年05月07日 5.98MB 下载

Effective STL

2010年04月07日 464KB 下载

走近 STL走近 STL走近 STL走近 STL

2011年05月18日 4.09MB 下载

STL Source

2009年12月18日 23.48MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭