-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorItemsSortingWithHashMap.cpp
More file actions
36 lines (30 loc) · 1.21 KB
/
VectorItemsSortingWithHashMap.cpp
File metadata and controls
36 lines (30 loc) · 1.21 KB
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) {
unordered_map<string, unordered_map<string, int>> orders_per_table;
set<string> food_types_ordered;
for(auto& order : orders) {
orders_per_table[order[1]][order[2]]++;
food_types_ordered.insert(order[2]);
}
vector<vector<string>> result_table;
vector<string> header;
header.push_back("Table");
for(auto& food_type: food_types_ordered){
header.push_back(food_type);
}
result_table.push_back(header);
for(auto& order : orders_per_table) {
vector<string> formated_orders;
formated_orders.push_back(order.first);
for(auto& food_type : food_types_ordered) {
formated_orders.push_back(to_string(order.second[food_type]));
}
result_table.push_back(formated_orders);
}
sort(result_table.begin() + 1, result_table.end(), [](const vector<string>& vs1, const vector<string>& vs2){
return stoi(vs1[0]) < stoi(vs2[0]);
});
return result_table;
}
};