您的位置:首页 > 其它

算法竞赛入门经典第五章例题5-4 Ananagrams UVA - 156

2018-01-07 13:31 316 查看
https://vjudge.net/problem/UVA-156

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)
string normal(string s) {
for (auto &x : s)
x = tolower(x);
sort(s.begin(), s.end());
return s;
}
int main()
{
#ifdef _DEBUG
//freopen("in", "rb", stdin);
//freopen("out", "wb", stdout);
#endif // _DEBUG
map<string, int> cnt;
vector<string> words,ans;
string s;
while (cin >> s && s!="#")
++cnt[normal(s)],words.push_back(s);
for (auto x : words)
if (cnt[normal(x)] == 1) ans.push_back(x);
sort(ans.begin(), ans.end());
for (auto x : ans)
cout << x << endl;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: