-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path898C. Phone Numbers.cpp
66 lines (56 loc) · 1.25 KB
/
898C. Phone Numbers.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
63
64
65
66
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
map<string, vector<string> > mp;
vector<string> tmp;
set<string> sol;
int main() {
cin >> n;
string name, cur;
int ent;
for(int i = 0; i < n; ++i) {
cin >> name >> ent;
for(int j = 0; j < ent; ++j) {
cin >> cur;
mp[name].push_back(cur);
}
}
cout << mp.size() << endl;
for(map<string, vector<string> >::iterator it = mp.begin(); it != mp.end(); ++it) {
tmp.clear();
tmp = it->second;
sort(tmp.begin(), tmp.end());
tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
sol.clear();
for(int i = 0; i < (int)tmp.size(); ++i) {
bool ok = true;
for(int j = 0; j < (int)tmp.size(); ++j) {
if(i != j) {
if(tmp[i] == tmp[j])
break;
if(tmp[j].size() > tmp[i].size()) {
bool ok1 = true;
for(int k = tmp[j].size() - 1, l = tmp[i].size() - 1; l >= 0; --k, --l) {
if(tmp[j][k] != tmp[i][l]) {
ok1 = false;
break;
}
}
if(ok1) {
ok = false;
break;
}
}
}
}
if(ok)
sol.insert(tmp[i]);
}
cout << it->first << ' ' << sol.size();
for(set<string>::iterator it = sol.begin(); it != sol.end(); ++it)
cout << ' ' << *it;
cout << endl;
}
return 0;
}