Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int* moveInMaze(char* str, int* is_ok);
  5.  
  6. int main() {
  7.     char request_string[200];
  8.     int* result;
  9.     int is_ok = 1;
  10.  
  11.     fgets(request_string,200,stdin);
  12.     result = moveInMaze(request_string, &is_ok);
  13.     if(!is_ok){
  14.         puts("invalid input command.\n");
  15.         return 1;
  16.     }
  17.     printf("%d %d", result[0], result[1]);
  18.     return 0;
  19. }
  20.  
  21. int* moveInMaze(char* command, int* is_ok){
  22.     #define ONE_NEW_LINE 1
  23.     int length = strlen(command) - ONE_NEW_LINE;
  24.     int static location[2] = {0,0};
  25.     for(int i=0; i<length; i++) {
  26.         switch (command[i])
  27.         {
  28.             case 'L': {
  29.                 location[0]--;
  30.                 break;
  31.             }
  32.             case 'R': {
  33.                 location[0]++;
  34.                 break;
  35.             }
  36.             case 'D': {
  37.                 location[1]--;
  38.                 break;
  39.             }
  40.             case 'U': {
  41.                 location[1]++;
  42.                 break;
  43.             }
  44.             default: {
  45.                 if(is_ok) *is_ok = 0;
  46.             }
  47.         }
  48.     }
  49.     return location;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement