【UVa 10815】Andy's First Dictionary

真的只用set和string就行了。

如果使用PASCAL的同学可能就要写个treap什么的了,还要用ansistring。

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

string s;
string now;
set<string> dict;

bool is_alpha(char &c)
{
    if (c >= 'a' && c <= 'z') return true;
    if (c >= 'A' && c <= 'Z')
    {
        c = c - 'A' + 'a';
        return true;
    }
    return false;
}

int main()
{
    dict.clear();
    while(cin >> s)
    {
        now = string("");
        for (int i = 0; i < s.length(); ++i)
            if (is_alpha(s[i])) now += s[i];
            else
            {
                if (now != "") dict.insert(now);
                now = string("");
            }
        if (now != "") dict.insert(now);
    }
    for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it)
        cout << *it << "\n";
    return 0;
}

 

posted @ 2015-08-14 10:37  albertxwz  阅读(160)  评论(0编辑  收藏  举报