2025. 4. 15


#include <string>
#include <vector>
#include <cmath>
using namespace std;
string solution(vector<int> numbers, string hand) {
string answer = "";
vector<pair<int, int>>call;
call.push_back({3,1});
pair<int, int>l = {3,0}, r = {3,2};
for(int i =0; i<3; ++i){
for(int j =0; j<3; ++j){
call.push_back({i,j});
}
}
for(auto x : numbers){
if(x%3==1){answer += "L"; l=call[x]; continue;}
if(x%3==0 && x!=0){answer += "R"; r=call[x]; continue;}
int cntR = abs(r.first-call[x].first)+abs(r.second-call[x].second);
int cntL = abs(l.first-call[x].first)+abs(l.second-call[x].second);
if(cntR != cntL) {
answer += cntR < cntL? "R" : "L";
cntR < cntL? r=call[x]:l=call[x];
}
else {
answer += hand == "right"? "R" : "L";
hand == "right"? r=call[x]:l=call[x];
}
}
return answer;
}
한시간 조금 덜 걸렸다!
0번 자리 행열 반대로 적어서 조금 더 오래걸림...
pair<int, int> 해서
int cntR = abs(r.first-call[x].first)+abs(r.second-call[x].second);
이거 구현하는 함수 만들려고 했는데
이게 생각보다 잘 안됐다.
이거는 공부를 조금 더 해야지
'C++ 문제풀기 > 백준-프로그래머스' 카테고리의 다른 글
| 프로그래머스 | 개인정보수집유효기간 (0) | 2025.06.19 |
|---|---|
| 프로그래머스 | 택배상자꺼내기 (2) | 2025.06.19 |
| 프로그래머스 | 나선형으로 배열하기 (0) | 2025.06.17 |
| 백준 | 1316. 그룹 단어 체커 (0) | 2025.06.17 |
| 백준 | 2941. 크로아티아 알파벳 (0) | 2025.06.17 |