fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define W 12
  5. #define H 10
  6. char map[H][W]={
  7. {1,1,1,1,1,1,1,1,1,1,1},
  8. {1,0,0,0,0,0,0,1,0,0,0,1},
  9. {1,0,1,1,0,0,1,1,0,1,0,1},
  10. {1,0,1,0,0,1,2,0,0,1,0,1},
  11. {1,0,0,0,0,0,1,1,1,0,0,1},
  12. {1,0,1,1,1,1,0,1,0,0,0,1},
  13. {1,0,1,0,0,0,0,1,0,0,0,1},
  14. {1,0,1,0,1,0,1,1,0,0,0,1},
  15. {1,0,0,0,1,0,0,0,0,0,0,1},
  16. {1,1,1,1,1,1,1,1,1,1,1,1},
  17. };
  18. void print_map(){
  19. int i,s;
  20. for(i=0;i<10;i++){
  21. for(s=0;s<12;s++){
  22. if(map[i][s]==1) printf("#");
  23. if(map[i][s]==0) printf(" ");
  24. if(map[i][s]==2) printf("G");
  25. }
  26. printf("\n");
  27. }
  28. }
  29.  
  30. void print_mini_map(int x,int y){
  31. for(int i=0;i<3;i++){
  32. if(map[y-1][i]==1) printf("#");
  33. if(map[y-1][i]==0) printf(".");
  34. if(map[y-1][i]==2) printf("G");
  35. }
  36. printf("\n");
  37. if(map[y][x-1]==1) printf("#");
  38. if(map[y][x-1]==0) printf(".");
  39. if(map[y][x-1]==2) printf("G");
  40. printf("o");
  41. if(map[y][x+1]==1) printf("#");
  42. if(map[y][x+1]==0) printf(".");
  43. if(map[y][x+1]==2) printf("G");
  44. printf("\n");
  45. for(int s=0;s<3;s++){
  46. if(map[y+1][s]==1) printf("#");
  47. if(map[y+1][s]==0) printf(".");
  48. if(map[y+1][s]==2) printf("G");
  49. }
  50. printf("\n");
  51. }
  52. int main(){
  53. int x,y,s;
  54. x=1,y=1;
  55. print_mini_map(x,y);
  56. if(map[y][x]==2){
  57. printf("Goal!!\n");
  58. exit(0);
  59. }
  60. printf("上8, 左4, 右6, 下2>\n");
  61. scanf("%d",&s);
  62. switch(s){
  63. case 2:
  64. if(map[y+1][x]!=1) y=y+1;
  65. else printf("(%d,%d)は通れません\n",y+1,x);
  66. break;
  67.  
  68. case 8:
  69. if(map[y-1][x]!=1) y=y-1;
  70. else printf("(%d,%d)は通れません\n",y-1,x);
  71. break;
  72.  
  73. case 4:
  74. if(map[y][x-1]!=1) x=x-1;
  75. else printf("(%d,%d)は通れません\n",y,x-1);
  76. break;
  77.  
  78. case 6:
  79. if(map[y][x+1]!=1) x=x+1;
  80. else printf("(%d,%d)は通れません\n",y,x+1);
  81. break;
  82.  
  83. default:
  84. printf("入力がおかしい\n");
  85. break;
  86. }
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0s 5320KB
stdin
8
stdout
###
#o.
#.#
上8, 左4, 右6, 下2>
(0,1)は通れません