-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1418.cpp
More file actions
36 lines (31 loc) · 980 Bytes
/
Copy path1418.cpp
File metadata and controls
36 lines (31 loc) · 980 Bytes
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
class Solution {
public:
vector<vector<string>> displayTable(vector<vector<string>> &orders) {
map<int, vector<string>> tables;
vector<vector<string>> res;
set<string> foods;
for (const auto &order : orders) {
tables[stoi(order[1])].push_back(order[2]);
foods.insert(order[2]);
}
unordered_map<string, int> pos;
int j = 1;
res.push_back({{"Table"}});
for (auto &food : foods) {
res[0].push_back(food);
pos[food] = j++;
}
for (auto &[table, foods] : tables) {
vector<int> row(res[0].size(), 0);
vector<string> rows;
rows.reserve(res[0].size());
for (const auto &food : foods)
row[pos[food]]++;
row[0] = table;
for (int r : row)
rows.push_back(to_string(r));
res.push_back(rows);
}
return res;
}
};