forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay Table of Food Orders in a Restaurant.cpp
60 lines (49 loc) · 1.48 KB
/
Display Table of Food Orders in a Restaurant.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Solution {
public:
vector<vector<string>> displayTable(vector<vector<string>>& orders) {
set<int> tables;
set<string> foodItems;
for (const auto& order : orders)
{
tables.insert(stoi(order[1]));
foodItems.insert(order[2]);
}
int pos = 1;
unordered_map<int,int> t_pos;
for (const auto& t : tables)
{
t_pos[t] = pos;
pos++;
}
pos = 1;
unordered_map<string,int> f_pos;
for (const auto& f : foodItems)
{
f_pos[f] = pos;
pos++;
}
vector<vector<string>> displayTable(tables.size()+1, vector<string>(foodItems.size()+1,"0"));
displayTable[0][0] = "Table";
auto it = tables.begin();
for (int x = 1; x < displayTable.size(); x++)
{
displayTable[x][0] = to_string(*it);
it++;
}
auto it_ = foodItems.begin();
for (int y = 1; y < displayTable[0].size(); y++)
{
displayTable[0][y] = *it_;
it_++;
}
for (const auto& order : orders)
{
int t = t_pos[stoi(order[1])];
int f = f_pos[order[2]];
int dec = stoi(displayTable[t][f]);
dec++;
displayTable[t][f] = to_string(dec);
}
return displayTable;
}
};