fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define W 8
  5. #define H 6
  6.  
  7. char map[H][W] = {
  8. {1,1,1,1,1,1,1,1},
  9. {1,0,0,0,0,0,0,1},
  10. {1,0,1,1,1,0,1,1},
  11. {1,0,0,0,0,1,0,1},
  12. {1,0,0,1,0,0,2,1},
  13. {1,1,1,1,1,1,1,1},
  14. };
  15.  
  16. void maze1(int x, int y, int depth)
  17. {
  18. int i;
  19.  
  20. for(i = 0; i < depth * 2; i++)
  21. {
  22. printf(" ");
  23. }
  24.  
  25. if(map[y][x] == 0)
  26. {
  27. printf("(%d,%d)\n", x, y);
  28.  
  29. maze1(x + 1, y, depth + 1); // 右
  30. maze1(x, y + 1, depth + 1); // 下
  31. }
  32. else if(map[y][x] == 1)
  33. {
  34. printf("(%d,%d)X\n", x, y);
  35. }
  36. else if(map[y][x] == 2)
  37. {
  38. printf("(%d,%d)OK\n", x, y);
  39. exit(0);
  40. }
  41. }
  42.  
  43. int main(void)
  44. {
  45. maze1(1, 1, 0);
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
(1,1)
  (2,1)
    (3,1)
      (4,1)
        (5,1)
          (6,1)
            (7,1)X
            (6,2)X
          (5,2)
            (6,2)X
            (5,3)X
        (4,2)X
      (3,2)X
    (2,2)X
  (1,2)
    (2,2)X
    (1,3)
      (2,3)
        (3,3)
          (4,3)
            (5,3)X
            (4,4)
              (5,4)
                (6,4)OK