@TOC

# # 题目描述

``````输入：orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]

Table,Beef Burrito,Ceviche,Fried Chicken,Water
3    ,0           ,2      ,1            ,0
5    ,0           ,1      ,0            ,1
10   ,1           ,0      ,0            ,0

``````

``````输入：orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]

``````

``````输入：orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]

``````

1. `1 <= orders.length <= 5 * 10^4`
2. `orders[i].length == 3`
3. `1 <= customerNamei.length, foodItemi.length <= 20`
4. `customerNamei``foodItemi` 由大小写英文字母及空格字符 `' '` 组成。
5. `tableNumberi` 是 1 到 500 范围内的整数。

# # 解题方法

## # 字典统计边的次数

1. 统计 foods 和 tables 分别为多少，并进行排序。
2. 统计每个桌的各个菜的次数
3. 把所有的桌的菜按照顺序拼接成列表

Python代码如下：

``````class Solution:
def displayTable(self, orders: List[List[str]]) -> List[List[str]]:
count = collections.defaultdict(dict)
foods = set()
tables = set()
for order in orders:
foods = sorted(list(foods))
cols = ["Table", ] + foods
res = []
res.append(cols)
for order in orders:
if order[2] not in count[order[1]]:
count[order[1]][order[2]] = 0
count[order[1]][order[2]] += 1
for table in sorted(list(tables)):
table = str(table)
tc = count[table]
line = [table,]
for food in foods:
if food not in tc:
line.append("0")
else:
line.append(str(tc[food]))
res.append(line)
return res
``````

# # 日期

2020 年 4 月 19 日 —— 近期比赛太多