-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUVA 156 Ananagrams.cpp
More file actions
41 lines (36 loc) · 914 Bytes
/
UVA 156 Ananagrams.cpp
File metadata and controls
41 lines (36 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
map<string, string> dict;
string word;
cin >> word;
while (word != "#") {
string sorted(word);
transform(sorted.begin(), sorted.end(), sorted.begin(), ::tolower);
sort(sorted.begin(), sorted.end());
if (dict.find(sorted) == dict.end()) {
dict[sorted] = string(word); // new
} else {
dict[sorted] = "#"; // exist
}
cin >> word;
}
vector<string> vec;
for (auto const& x : dict) {
if (x.second != "#") vec.push_back(x.second);
}
sort(vec.begin(), vec.end());
for (string const& w : vec) {
cout << w << endl;
}
return 0;
}