-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_01.cpp
More file actions
54 lines (46 loc) · 1020 Bytes
/
04_01.cpp
File metadata and controls
54 lines (46 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/***********************
* date : 2022-04-05
* topic : 구현
* feedback :
* 1. 공간을 벗어나는 경우 고려 x
* 2. 갯수를 알 수 없는 char 배열 입력은 string으로 받기
* time : 15 min
************************/
#include <iostream>
//#include <istream>
#include <string>
using namespace std;
int main_04_01()
{
// 입력 받기
int cnt;
cin >> cnt;
cin.ignore(); // 버퍼 비우기
/*
char path[100];
cin.getline(path, 100);
*/
string path;
getline(cin, path);
// 방향 설정
char direct[4] = {'L', 'R', 'U', 'D'};
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
// 최초 좌표
int xx = 1;
int yy = 1;
// 경로 이동
for(int x=0;x<path.length();x++){
for(int y=0;y<4;y++){
if(path[x] == direct[y]){
xx += dx[y];
yy += dy[y];
}
}
// 공간을 벗어나는 경우
if(xx < 1 || yy < 1 || xx > cnt || yy > cnt) continue;
}
// 좌표 출력
cout << xx << " " << yy;
return 0;
}