We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 20751e7 commit fe4a3e9Copy full SHA for fe4a3e9
Baekjoon/Q20436.py
@@ -0,0 +1,40 @@
1
+# link: https://www.acmicpc.net/problem/20436
2
+# 다시 풀어볼 것
3
+
4
+sl, sr = map(str, input().split())
5
+data = input()
6
+result = 0
7
8
+# x, y 좌표 찾는 함수
9
+def find_location(word):
10
+ keyboard = [
11
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
12
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'],
13
+ ['z', 'x', 'c', 'v', 'b', 'n', 'm']
14
+ ]
15
16
+ for i, key in enumerate(keyboard):
17
+ if word in key:
18
+ x = key.index(word)
19
+ y = i
20
+ return x, y
21
22
+# 키보드 왼쪽 영역에 있는 글자
23
+left_field = 'qwertasdfgzxcv'
24
25
+# data 순회하면서 거리 찾기
26
+for d in data:
27
+ if sl == d or sr == d: result += 1
28
+ else:
29
+ slx, sly = find_location(sl)
30
+ srx, sry = find_location(sr)
31
+ dx, dy = find_location(d)
32
33
+ if d in left_field:
34
+ result += abs(slx-dx) + abs(sly-dy) + 1
35
+ sl, slx, sly = d, dx, dy
36
37
+ result += abs(srx-dx) + abs(sry-dy) + 1
38
+ sr, srx, sry = d, dx, dy
39
40
+print(result)
0 commit comments