-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·57 lines (46 loc) · 1.08 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·57 lines (46 loc) · 1.08 KB
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
55
56
57
#include <bits/stdc++.h>
using namespace std;
int main()
{
while (true)
{
int W, L;
cin >> W >> L;
if (W == 0 && L == 0)
break;
int n;
cin >> n;
int x = 0, y = 0;
int x_real = 0, y_real = 0;
for (int i = 0; i < n; ++i)
{
char dir;
int dist;
cin >> dir >> dist;
if (dir == 'u')
{
y += dist;
y_real = min(y_real + dist, L - 1);
}
if (dir == 'd')
{
y -= dist;
y_real = max(y_real - dist, 0);
}
if (dir == 'l')
{
x -= dist;
x_real = max(x_real - dist, 0);
}
if (dir == 'r')
{
x += dist;
x_real = min(x_real + dist, W - 1);
}
}
cout << "Robot thinks " << x << " " << y << endl;
cout << "Actually at " << x_real << " " << y_real << endl
<< endl;
}
return 0;
}