-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLv1_키패드누르기.cpp
More file actions
79 lines (65 loc) · 2.2 KB
/
Lv1_키패드누르기.cpp
File metadata and controls
79 lines (65 loc) · 2.2 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int dist[13][13];
string solution(vector<int> numbers, string hand) {
string answer = "";
int left = 10;
int right = 12;
dist[1][2] = dist[3][2] = dist[4][5] = dist[6][5] = dist[7][8] = dist[9][8] = dist[10][11] = dist[12][11] = 1;
dist[1][5] = dist[3][5] = dist[4][2] = dist[4][8] = dist[6][2] = dist[6][8] = dist[7][5] = dist[9][5] = dist[7][11] = dist[9][11] = dist[10][8] = dist[12][8] = 2;
dist[1][8] = dist[3][8] = dist[4][11] = dist[6][11] = dist[7][2] = dist[9][2] = dist[10][5] = dist[12][5] = 3;
dist[1][11] = dist[3][11] = dist[10][2] = dist[12][2] = 4;
for (auto a : numbers) {
if (a == 1 || a == 4 || a == 7) {
answer += "L";
left = a;
}
else if(a == 3 || a == 6 || a == 9) {
answer += "R";
right = a;
}else{
int number = a;
if (number == 0)
number = 11;
int left_diff = 0;
int right_diff = 0;
// ?¼ì†ê³¼ì˜ 거리
if (left == 2 || left == 5 || left == 8 || left == 11)
left_diff = abs(number - left) / 3;
else
left_diff = dist[left][number];
// ?¤ë¥¸?ê³¼??거리
if (right == 2 || right == 5 || right == 8 || right == 11)
right_diff = abs(number - right) / 3;
else
right_diff = dist[right][number];
if (left_diff < right_diff) {
answer += "L";
left = number;
}
else if (left_diff > right_diff) {
answer += "R";
right = number;
}
else {
if (hand == "left") {
answer += "L";
left = number;
}
else {
answer += "R";
right = number;
}
}
}
}
return answer;
}
int main() {
vector<int> arr = { 1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5 };
string hand = "right";
cout << solution(arr, hand);
return 0;
}