-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path156.cpp
62 lines (58 loc) · 1.54 KB
/
156.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<string>
#include<iostream>
#include<algorithm>
#include<cctype>
using namespace std;
typedef struct word {
int place;
string str;
} w;
bool cmpstr(w a, w b){
return lexicographical_compare(a.str.begin(), a.str.end(), b.str.begin(), b.str.end());
}
bool cmpout(string a, string b){
return lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
int main(){
string ori[1000], tmp, out[1000];
w pro[1000], buf;
int i = 0, finddup = 1, k = 0;
while (cin >> tmp, tmp.compare("#")) {
ori[i].assign(tmp);
pro[i].str.assign(tmp);
for (string::iterator it = pro[i].str.begin(); it != pro[i].str.end(); it++){
*it = tolower(*it);
}
sort(pro[i].str.begin(), pro[i].str.end());
pro[i].place = i;
i++;
}
sort(pro, pro + i, cmpstr);
for (int j = 0; j < i; j++){
if (!j){
buf.str.assign(pro[j].str);
buf.place = pro[j].place;
} else {
if (buf.str.compare(pro[j].str)){
if (finddup) {
out[k].assign(ori[buf.place]);
k++;
} else {
finddup = 1;
}
buf.str.assign(pro[j].str);
buf.place = pro[j].place;
} else {
finddup = 0;
}
}
}
if (finddup){
out[k++].assign(ori[buf.place]);
}
sort(out, out + k, cmpout);
for (int i = 0; i < k; i++){
cout << out[i] << '\n';
}
return 0;
}