-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11470.go
54 lines (48 loc) · 963 Bytes
/
11470.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
54
// UVa 11470 - Square Sums
package main
import (
"fmt"
"os"
"strconv"
"strings"
)
func add(square [][]int, n, i int) int {
var sum int
for j := i; j < n-i; j++ {
sum += square[i][j]
if i != n-i-1 {
sum += square[n-i-1][j]
}
}
for j := i + 1; j < n-i-1; j++ {
sum += square[j][i] + square[j][n-i-1]
}
return sum
}
func solve(n int, square [][]int) []string {
var sums []string
for i := 0; i < (n+1)/2; i++ {
sums = append(sums, strconv.Itoa(add(square, n, i)))
}
return sums
}
func main() {
in, _ := os.Open("11470.in")
defer in.Close()
out, _ := os.Create("11470.out")
defer out.Close()
var n int
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
square := make([][]int, n)
for i := range square {
square[i] = make([]int, n)
for j := range square[i] {
fmt.Fscanf(in, "%d", &square[i][j])
}
}
fmt.Fprintf(out, "Case %d: %s\n", kase, strings.Join(solve(n, square), " "))
}
}