-
Notifications
You must be signed in to change notification settings - Fork 502
/
b.go
47 lines (42 loc) · 828 Bytes
/
b.go
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
package main
import (
"sort"
"strconv"
)
func displayTable(orders [][]string) (ans [][]string) {
uniqueInPlace := func(a []string) []string {
n := len(a)
j := 0
for i := 1; i < n; i++ {
if a[j] != a[i] {
j++
a[j] = a[i]
}
}
return a[:j+1]
}
foods := []string{}
tables := [501]map[string]int{}
for i := range tables {
tables[i] = map[string]int{}
}
for _, order := range orders {
tt, fd := order[1], order[2]
t, _ := strconv.Atoi(tt)
foods = append(foods, fd)
tables[t][fd]++
}
sort.Strings(foods)
foods = uniqueInPlace(foods)
ans = append(ans, append([]string{"Table"}, foods...))
for i, m := range tables {
if len(m) > 0 {
a := []string{strconv.Itoa(i)}
for _, fd := range foods {
a = append(a, strconv.Itoa(m[fd]))
}
ans = append(ans, a)
}
}
return
}