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