uvaoj 10815 Andy's First Dictionary set的基本使用

uvaoj 10815 Andy's First Dictionary set的基本使用
將單詞去重後按照字典序輸出。
代碼如下:
/*************************************************************************
	> File Name: 10815.cpp
	> Author: gwq
	> Mail: [email protected] 
	> 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;
}


發佈了124 篇原創文章 · 獲贊 15 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章