#include #include #include 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