-
Notifications
You must be signed in to change notification settings - Fork 0
/
baconeggsandspam.cpp
64 lines (49 loc) · 1.08 KB
/
baconeggsandspam.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
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
#include <algorithm>
using namespace std;
typedef unsigned short int usint;
usint n;
string x, y, ans;
vector <vector <string>> v;
vector <string> tmp;
set <string> item;
bool compare(vector <string> a, vector <string> b) {
return a[0] < b[0];
}
int main() {
for(;;) {
cin >> n;
cin.ignore();
if(n == 0) break;
while(n--) {
getline(cin, x);
istringstream iss(x);
while(getline(iss, y, ' ')) {
tmp.push_back(y);
}
v.push_back(tmp);
tmp.erase(tmp.begin());
for(auto it=tmp.begin(); it != tmp.end(); ++it) {
item.insert(*it);
}
tmp.clear();
}
sort(v.begin(), v.end(), compare);
for(auto it=item.begin(); it != item.end(); ++it) {
ans = *it + " ";
for(usint i=0; i<v.size(); ++i) {
if(find(v[i].begin(), v[i].end(), *it) != v[i].end()) {
ans += v[i][0] + " ";
}
}
cout << ans << endl;
}
item.clear();
v.clear();
cout << endl;
}
return 0;
}