-
Notifications
You must be signed in to change notification settings - Fork 1
/
02.go
38 lines (35 loc) · 810 Bytes
/
02.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
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func maxi(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
sum, powers := 0, 0
for scanner.Scan() {
game := strings.Split(scanner.Text(), ": ")
mins := map[string]int{}
for _, show := range strings.Split(game[1], ";") {
for _, c := range strings.Split(show, ",") {
cubes := strings.Split(strings.TrimSpace(c), " ")
n, _ := strconv.ParseInt(cubes[0], 10, 32)
mins[cubes[1]] = maxi(mins[cubes[1]], int(n))
}
}
if mins["red"] <= 12 && mins["green"] <= 13 && mins["blue"] <= 14 {
n, _ := strconv.ParseInt(strings.Split(game[0], " ")[1], 10, 32)
sum += int(n)
}
powers += mins["red"] * mins["green"] * mins["blue"]
}
fmt.Println(sum, powers)
}