Description
Submission
class Solution {
public:
vector<vector<string>> displayTable(vector<vector<string>>& orders) {
map<int, unordered_map<string, int>> table;
set<string> foods;
for(auto& order: orders) {
int tid = stoi(order[1]);
string food = order[2];
table[tid][food]++;
foods.insert(food);
}
vector<vector<string>> rets;
rets.push_back({"Table"});
copy(foods.begin(), foods.end(), back_inserter(rets[0]));
for(auto [tid, f]: table) {
vector<string> cur;
cur.push_back(to_string(tid));
for(auto food: foods) {
cur.push_back(to_string(f[food]));
}
rets.push_back(cur);
}
return rets;
}
};