Click
Here to go back to the homepage.
Bacon, Eggs, and Spam Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef TESTING
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
string line, name, food;
getline(cin, line);
int people = stoi(line);
map<string, vector<string>> mapp;
do{
while(people--){
getline(cin, line);
istringstream wordstream(line);
wordstream >> name;
while(wordstream >> food){
auto it = mapp.find(food);
if(it == mapp.end()){
mapp.insert({food, {name}});
} else {
(*it).second.push_back(name);
}
}
}
for(auto i: mapp){
cout << i.first << " ";
sort(i.second.begin(), i.second.end());
for(auto j: i.second){
cout << j << " ";
}
i.second.clear();
cout << endl;
}
mapp.clear();
getline(cin, line);
people = stoi(line);
if(people){
cout << endl;
}
} while(people);
return 0;
}