๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[C++/PGS] [PCCP ๋ชจ์˜๊ณ ์‚ฌ #2] 1๋ฒˆ - ์‹ค์Šต์šฉ ๋กœ๋ด‡

xxilliant 2025. 4. 28. 16:26
728x90
๋ฐ˜์‘ํ˜•

 

https://school.programmers.co.kr/learn/courses/15009/lessons/121687

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

SW๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ‰๊ฐ€, ๊ต์œก, ์ฑ„์šฉ๊นŒ์ง€ Total Solution์„ ์ œ๊ณตํ•˜๋Š” ๊ฐœ๋ฐœ์ž ์„ฑ์žฅ์„ ์œ„ํ•œ ๋ฒ ์ด์Šค์บ ํ”„

programmers.co.kr


ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค PCCP ๋ชจ์˜๊ณ ์‚ฌ 2ํšŒ - 1๋ฒˆ

์†Œ์š”์‹œ๊ฐ„ ์•ฝ 7๋ถ„

์กฐ๊ฑด๋ฌธ, ๋‹จ์ˆœ ๊ตฌํ˜„, ์ถ”์ • ๋‚œ์ด๋„๋Š” level 1

 

๋‚˜์˜ ํ’€์ด

#include <string>
#include <vector>

using namespace std;

vector<int> solution(string command) {
    vector<int> answer;
    int dx[4] = {0,1,0,-1}; // ์‹œ๊ณ„๋ฐฉํ–ฅ up, right, down, left
    int dy[4] = {1,0,-1,0};
    int state = 0; // dx/dy ์ธ๋ฑ์Šค
    int now[2] = {0,0};
    for(int i=0; i<command.length(); ++i){
        switch(command[i]){
            case 'R':
                state = (state+1)%4;
                break;
            case 'L':
                state = ((state+4)-1)%4;
                break;
            case 'G':
                now[0] += dx[state];
                now[1] += dy[state];
                break;
            case 'B':
                now[0] -= dx[state];
                now[1] -= dy[state];
                break;
            default: break;
        }
    }
    answer.push_back(now[0]);
    answer.push_back(now[1]);
    return answer;
}

728x90
๋ฐ˜์‘ํ˜•