#include <string>
#include <vector>
using namespace std;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int GetDirection(char direction)
{
switch(direction)
{
case 'S':
return 0;
case 'E':
return 1;
case 'N':
return 2;
case 'W':
return 3;
}
}
vector<int> solution(vector<string> park, vector<string> routes) {
int h = park.size(); // 세로
int w = park.at(0).size(); // 가로
int x = 0;
int y = 0;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
if(park[i][j] == 'S') {
x = i;
y = j;
}
}
}
for(auto route : routes) {
int dir = GetDirection(route.at(0)); // 동서남북 방향 알아내기
int count = route.at(2) - '0';
int cx = x + dx[dir] * count;
int cy = y + dy[dir] * count;
bool flag = false;
// 공원을 벗어나면 x
if(cx < 0 || cx >= h || cy < 0 || cy >= w)
continue;
// 중간에 장애물 만나면 x
for(int idx = 1; idx <= count; idx++) {
cx = x + dx[dir] * idx;
cy = y + dy[dir] * idx;
if(park[cx][cy] == 'X') {
flag = true;
break;
}
}
if(!flag) {
x = cx;
y = cy;
}
}
return {x,y};
}