C++ 스터디

DongGeon Gwak·2025년 5월 20일

C++

목록 보기
2/17

answer[0] = east;
answer[1] = north;
각각 X,Y 좌표를 의미한다.

#include <string>
#include <vector>

using namespace std;

vector<int> solution(string route) {
    int east = 0;
    int north = 0;
    vector<int> answer(2);
    for(int i=0; i<route.length(); i++){
        switch(route[i]){
            case 'N':
                north++;
                break;
            case 'S':
	              north--;
                break;
            case 'E':
                east++;
                break;
            case 'W':
                east--;
                break;
        }
    }
    answer[0] = east;
    answer[1] = north;
    return answer;
}코드를 입력하세요
profile
아싸라비야

0개의 댓글