forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.cpp
More file actions
38 lines (34 loc) Β· 916 Bytes
/
1.cpp
File metadata and controls
38 lines (34 loc) Β· 916 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
#include <bits/stdc++.h>
using namespace std;
// Nμ μ
λ ₯λ°κΈ°
int n;
string plans;
int x = 1, y = 1;
// L, R, U, Dμ λ°λ₯Έ μ΄λ λ°©ν₯
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
char moveTypes[4] = {'L', 'R', 'U', 'D'};
int main(void) {
cin >> n;
cin.ignore(); // λ²νΌ λΉμ°κΈ°
getline(cin, plans);
// μ΄λ κ³νμ νλμ© νμΈ
for (int i = 0; i < plans.size(); i++) {
char plan = plans[i];
// μ΄λ ν μ’ν ꡬνκΈ°
int nx = -1, ny = -1;
for (int j = 0; j < 4; j++) {
if (plan == moveTypes[j]) {
nx = x + dx[j];
ny = y + dy[j];
}
}
// 곡κ°μ λ²μ΄λλ κ²½μ° λ¬΄μ
if (nx < 1 || ny < 1 || nx > n || ny > n) continue;
// μ΄λ μν
x = nx;
y = ny;
}
cout << x << ' ' << y << '\n';
return 0;
}