-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaconeggsandspam.cpp
40 lines (40 loc) · 1.04 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
// GitHub: EntityPlantt/Kattis
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
int main() {
int n;
while (true) {
cin >> n;
if (n == 0) {
break;
}
map <string, vector <string>> out;
set <string> allOrders;
string s, orderer;
cin.ignore();
while (n--) {
getline(cin, s);
orderer = s.substr(0, s.find(' '));
s = s.substr(s.find(' ') + 1);
while (s.find(' ') < string::npos) {
allOrders.insert(s.substr(0, s.find(' ')));
out[s.substr(0, s.find(' '))].push_back(orderer);
s = s.substr(s.find(' ') + 1);
}
allOrders.insert(s);
out[s].push_back(orderer);
}
for (string order : allOrders) {
cout << order;
for (string orderer : out[order]) {
cout << ' ' << orderer;
}
cout << '\n';
}
cout << '\n';
}
return 0;
}