uvaoj 10815 Andy's First Dictionary set的基本使用
将单词去重后按照字典序输出。
代码如下:
/*************************************************************************
> File Name: 10815.cpp
> Author: gwq
> Mail: gwq5210@qq.com
> Created Time: 2015年01月20日 星期二 14时34分22秒
************************************************************************/
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#define INF (INT_MAX / 10)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define pb push_back
#define sz(a) ((int)(a).size())
using namespace std;
typedef set<int> si;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
const double esp = 1e-5;
set<string> dict;
int main(int argc, char *argv[])
{
string str, buf;
while (cin >> str) {
int len = str.length();
for (int i = 0; i < len; ++i) {
if (isalpha(str[i])) {
str[i] = tolower(str[i]);
} else {
str[i] = ' ';
}
}
stringstream ss(str);
while (ss >> buf) {
dict.insert(buf);
}
}
for (set<string>::iterator it = dict.begin(); it != dict.end(); ++it) {
cout << *it << endl;
}
return 0;
}