您的位置:首页 > 其它

算典05_例题_03_UVA-10815

2017-04-01 19:05 288 查看

Andy’s First Dictionary

题意

输入一些文本,将其中出现过的单词(大小写都换成小写),按字典序输出

题解

水题。集合set的用法,set中的元素默认是有序的

这题之所以可以用set就是考虑到输入的文本中可能会出现大量重复的单词,所以用set即可避免重复,其实不用set只要能去掉重复的单词也是可以的

#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>

using namespace std;
const int maxn = 1e2 + 5;
const int INF = (1<<31)-1;
#define met(a, b) memset(a, b, sizeof(a));
#define IN freopen("in.txt", "r", stdin);
typedef long long LL;

string s, a;
set<string> Set;

int main(){
#ifdef _LOCAL
IN;
#endif // _LOCAL

while(cin>>s) {
for(int i = 0; i < s.length(); ++i) {
if(isalpha(s[i])) s[i] = tolower(s[i]);
else s[i] = ' ';
}
stringstream ss(s);
while(ss >> a) Set.insert(a);
}
set<string>::iterator it = Set.begin();
for(; it!= Set.end(); ++it) {
cout << (*it) <<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: