-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkakao-1.cpp
More file actions
67 lines (63 loc) · 1.3 KB
/
kakao-1.cpp
File metadata and controls
67 lines (63 loc) · 1.3 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
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
using namespace std;
string solution(vector<int> numbers, string hand) {
string answer = "";
int dist1=0; int dist2=0;
int l1=3; int l2=0;
int r1=3; int r2=2;
int phone[4][3] ={1,2,3,4,5,6,7,8,9,-1,0,-1};
int row=-1,col=-1,sign=-1;
for (vector<int>::iterator ptr=numbers.begin();ptr!=numbers.end();++ptr){
int temp = *ptr;
sign=-1;
for(int i=0;i<4;i++){
for(int j=0;j<3;j++){
if(temp==phone[i][j]){
row=i; col=j;
sign=1;
break;
}
}
if(sign!=-1) break;
}
cout<<"row : "<<row<<" col : "<<col<<'\n';
if(col==0){
answer.append("L");
l1=row;l2=col;
}
else if(col==2){
answer.append("R"); r1=row;r2=col;
}
else{
dist1 = abs(row-l1) + abs(col-l2); //L
dist2 = abs(row-r1) + abs(col-r2); //R
if(dist1>dist2) {
answer.append("R"); r1=row;r2=col;
}
else if (dist1<dist2) {
answer.append("L"); l1=row;l2=col;
}
else {
if(hand == "right") {
answer.append("R"); r1=row;r2=col;
}
else {
answer.append("L"); l1=row;l2=col;
}
}
}
}
return answer;
}
int main(){
vector<int> numbers;
for(int i=0;i<8;i++){
int t;
cin>>t;
numbers.push_back(t);
}
cout<<solution(numbers,"right");
}