-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_20436.py
More file actions
54 lines (50 loc) · 1.28 KB
/
Copy pathbj_20436.py
File metadata and controls
54 lines (50 loc) · 1.28 KB
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
import sys
sys.stdin = open('bj_20436_in.txt', 'r')
input = sys.stdin.readline
left = set(['q', 'w', 'e', 'r', 't', 'a', 's', 'd', 'f', 'g', 'z', 'x', 'c', 'v'])
coords = {
'q': (0, 0),
'w': (0, 1),
'e': (0, 2),
'r': (0, 3),
't': (0, 4),
'y': (0, 5),
'u': (0, 6),
'i': (0, 7),
'o': (0, 8),
'p': (0, 9),
'a': (1, 0),
's': (1, 1),
'd': (1, 2),
'f': (1, 3),
'g': (1, 4),
'h': (1, 5),
'j': (1, 6),
'k': (1, 7),
'l': (1, 8),
'z': (2, 0),
'x': (2, 1),
'c': (2, 2),
'v': (2, 3),
'b': (2, 4),
'n': (2, 5),
'm': (2, 6)
}
left_hand, right_hand = input().strip().split()
# print(left_hand, right_hand)
cmd = input().strip()
# print(cmd)
cnt = 0
for c in cmd:
# print(c)
if c in left: #왼쪽 타자 영역이면
# print(coords[left_hand])
# print(coords[c])
cnt += abs(coords[left_hand][0] - coords[c][0]) + abs(coords[left_hand][1] - coords[c][1]) +1 #이동거리 + 1(출력시간)
left_hand = c
else: #오른쪽 타자 영역이면
# print(coords[right_hand])
# print(coords[c])
cnt += abs(coords[right_hand][0] - coords[c][0]) + abs(coords[right_hand][1] - coords[c][1]) +1 #이동거리 + 1(출력시간)
right_hand = c
print(cnt)