2023-12-01 13:35:13 +01:00

71 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void move(char d, int s, int w, int l, int *rx, int *ry, int *x, int *y) {
if (d == 'u') {
*ry += s;
if (*y + s < l) {
*y += s;
} else {
*y = l-1;
}
} else if (d == 'd') {
*ry -= s;
if (*y - s >= 0) {
*y -= s;
} else {
*y = 0;
// WOW. WOW. WOW. WOW. WOW.
}
} else if (d == 'l') {
*rx -= s;
if (*x - s >= 0) {
*x -= s;
} else if (*x - s < 0) {
*x = 0;
}
} else if (d == 'r') {
*rx += s;
if (*x + s < w) {
*x += s;
} else {
*x = w-1;
}
}
}
int main(int argc, char **argv) {
int w = -1, l = -1;
int printed = 0;
while (1) {
// Handle room size
scanf("%d %d", &w, &l);
if (w == 0 && l == 0) {
return 0;
}
// Initialize actual and robot coords
int x = 0, y = 0, rx = 0, ry = 0;
int moves;
// Do moves
scanf("%d", &moves);
for (int i=0; i<moves; i++) {
// Take direction and steps(in meters or whatever)
char d;
int s;
scanf(" %c %d", &d, &s);
// Dear C, I hope you fucking die in a fire. What the fuck is the difference between "%c" and " %c" you pretentious ancient piece of shit. :P
// P.S. Why the fuck is my code not working?1/1/?!?1/
// Move
move(d, s, w, l, &rx, &ry, &x, &y);
}
if (printed) {
printf("\n");
} else {
printed = 1;
}
printf("Robot thinks %d %d\nActually at %d %d\n", rx, ry, x, y);
}
return 0;
}