forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboundingrobots.cpp
54 lines (45 loc) · 1.2 KB
/
boundingrobots.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
int range(int small, int large, int val) {
int ans = val;
ans = min(large, ans);
ans = max(small, ans);
return ans;
}
int main() {
int w, l;
while(cin >> w && cin >> l && (w != 0 && l != 0)) {
int n;
cin >> n;
int actualX = 0, robotX = 0;
int actualY = 0, robotY = 0;
for(int i = 0; i < n; i++) {
char dir;
cin >> dir;
int dist;
cin >> dist;
if(dir == 'u') {
robotY += dist;
actualY += dist;
}
if(dir == 'd') {
robotY -= dist;
actualY -= dist;
}
if(dir == 'l') {
robotX -= dist;
actualX -= dist;
}
if(dir == 'r') {
robotX += dist;
actualX += dist;
}
actualY = range(0, l-1, actualY);
actualX = range(0, w-1, actualX);
}
cout << "Robot thinks " << robotX << " " << robotY << endl;
cout << "Actually at " << actualX << " " << actualY << endl;
cout << endl;
}
}