-
Notifications
You must be signed in to change notification settings - Fork 27
/
637.go
62 lines (56 loc) · 1.01 KB
/
637.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
55
56
57
58
59
60
61
62
// UVa 637 - Booklet Printing
package main
import (
"fmt"
"io"
"os"
)
var pages = [2]string{"front", "back "}
func solve(out io.Writer, n int) {
sheet := n / 4
if n%4 != 0 {
sheet++
}
blanks := sheet*4 - n
left := true
fmt.Fprintf(out, "Printing order for %d pages:\n", n)
here:
for pageToPrint, i := 1, 1; i <= sheet; i++ {
for _, page := range pages {
fmt.Fprintf(out, "Sheet %d, %s: ", i, page)
if blanks > 0 {
if left {
fmt.Fprintf(out, "Blank, %d\n", pageToPrint)
} else {
fmt.Fprintf(out, "%d, Blank\n", pageToPrint)
}
blanks--
} else {
if left {
fmt.Fprintf(out, "%d, %d\n", n, pageToPrint)
} else {
fmt.Fprintf(out, "%d, %d\n", pageToPrint, n)
}
n--
}
pageToPrint++
if pageToPrint > n {
break here
}
left = !left
}
}
}
func main() {
in, _ := os.Open("637.in")
defer in.Close()
out, _ := os.Create("637.out")
defer out.Close()
var n int
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
solve(out, n)
}
}