1 분 소요

🗒️ 캐릭터의 좌표

#include <string>
#include <vector>
using namespace std;

vector<int> solution(vector<string> keyinput, vector<int> board) 
{
    vector<int> answer = {0, 0};
    for(string& dir : keyinput)
    {
        if(dir=="left")
            answer[0] = max(answer[0]-1, -board[0]/2);
        else if(dir=="right")
            answer[0] = min(answer[0]+1, board[0]/2);
        else if(dir=="down")
            answer[1] = max(answer[1]-1, -board[1]/2);
        else if(dir=="up")
            answer[1] = min(answer[1]+1, board[1]/2);
    }
    
    return answer;
}

업데이트:

댓글남기기