-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path743.go
55 lines (48 loc) · 770 Bytes
/
743.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
// UVa 743 - The MTM Machine
package main
import (
"fmt"
"os"
"strings"
)
func produce(s string) string {
if s == "2" {
return s
}
return s[1:]
}
func associate(s string) string {
if s == "" {
return s
}
return s + "2" + s
}
func solve(s string) string {
switch {
case strings.Contains(s, "0"):
return ""
case s[0] == '3':
return associate(solve(s[1:]))
case len(s) > 1 && s[0] == '2':
return produce(s)
default:
return ""
}
}
func main() {
in, _ := os.Open("743.in")
defer in.Close()
out, _ := os.Create("743.out")
defer out.Close()
var n int64
for {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
if s := solve(fmt.Sprint(n)); s != "" {
fmt.Fprintln(out, s)
} else {
fmt.Fprintln(out, "NOT ACCEPTABLE")
}
}
}