fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. const char *commands[] = {"left", "right", "up", "down", NULL};
  7. char inp_command[6];
  8. int dir[] = {-1, 0, 1, 0, 0, -1, 0, 1};
  9. int x = 0, y = 0;
  10.  
  11. while(scanf("%5s", inp_command) != EOF)
  12. {
  13. for (int i = 0; commands[i]; i++)
  14. if (!strcmp(inp_command, commands[i]))
  15. {
  16. x += dir[i * 2], y += dir[i * 2 + 1];
  17. break;
  18. }
  19. }
  20. printf("%d %d\n", x, y);
  21. return 0;
  22. }
Success #stdin #stdout 0s 9424KB
stdin
down
down
up
right
left
stdout
0 1