-
Notifications
You must be signed in to change notification settings - Fork 0
/
67.go
53 lines (47 loc) · 786 Bytes
/
67.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
48
49
50
51
52
53
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func max(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
f, err := os.Open("67.txt")
if err != nil {
return
}
data := make([][]int, 0)
reader := bufio.NewReader(f)
for {
line, err := reader.ReadString('\n')
if err != nil {
break
}
line = strings.TrimSpace(line)
row := make([]int, 0)
pieces := strings.Split(line, " ")
for _, value := range pieces {
i, err := strconv.Atoi(value)
if err != nil {
return
}
row = append(row, i)
}
data = append(data, row)
}
rows := len(data)
for i := rows - 2; i >= 0; i-- {
cmns := len(data[i])
for j := 0; j < cmns; j++ {
data[i][j] += max(data[i+1][j], data[i+1][j+1])
}
}
fmt.Println(data[0][0])
}