-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain2.go
53 lines (47 loc) · 775 Bytes
/
main2.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"
)
var pad = [][]string{
{" ", " ", "1", " ", " "},
{" ", "2", "3", "4", " "},
{"5", "6", "7", "8", "9"},
{" ", "A", "B", "C", " "},
{" ", " ", "D", " ", " "},
}
func main() {
pin := ""
// start from '5'
x, y := 2, 0
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
for _, c := range scanner.Text() {
switch c {
case 'U':
x1 := x - 1
if x1 >= 0 && pad[x1][y] != " " {
x = x1
}
case 'D':
x1 := x + 1
if x1 < 5 && pad[x1][y] != " " {
x = x1
}
case 'R':
y1 := y + 1
if y1 < 5 && pad[x][y1] != " " {
y = y1
}
case 'L':
y1 := y - 1
if y1 >= 0 && pad[x][y1] != " " {
y = y1
}
}
}
pin += pad[x][y]
}
fmt.Println(pin)
}