fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6. void printMaze(const vector<string>& maze, int r, int c, int step) {
  7. cout << "===== Step " << step << " | Position (" << r << "," << c << ") =====\n";
  8. for (auto &row : maze) cout << row << "\n";
  9. cout << "\n";
  10. }
  11.  
  12. int main() {
  13. vector<string> maze = {
  14. "##########",
  15. "#@.......#",
  16. "#.######.#",
  17. "#......#.#",
  18. "###.##.#.#",
  19. "#...#....#",
  20. "#.#.###..#",
  21. "#.#.....##",
  22. "#.#.E....#",
  23. "##########"
  24. };
  25.  
  26. int r = 1, c = 1; // start position
  27. int er = 8, ec = 3; // exit position
  28.  
  29. string moves;
  30. cin >> moves; // <-- WPROWADZASZ STEROWANIE JAKO TEKST, np: SSSDDWWAAS
  31.  
  32. int step = 0;
  33. printMaze(maze, r, c, step);
  34.  
  35. for (char key : moves) {
  36. int nr = r, nc = c;
  37.  
  38. if (key == 'w' || key == 'W') nr--;
  39. else if (key == 's' || key == 'S') nr++;
  40. else if (key == 'a' || key == 'A') nc--;
  41. else if (key == 'd' || key == 'D') nc++;
  42. else continue; // ignoruj inne znaki
  43.  
  44. // blokada o ścianę
  45. if (maze[nr][nc] == '#')
  46. continue;
  47.  
  48. // ruch
  49. maze[r][c] = '.';
  50. r = nr;
  51. c = nc;
  52. maze[r][c] = '@';
  53. step++;
  54.  
  55. printMaze(maze, r, c, step);
  56.  
  57. // sprawdzenie wyjścia
  58. if (r == er && c == ec) {
  59. cout << "BRAWO!\n";
  60. return 0;
  61. }
  62. }
  63.  
  64. cout << "SPROBUJ JESZCZE RAZ\n";
  65. return 0;
  66. }
Success #stdin #stdout 0.01s 5288KB
stdin
dddddddsssssassaaa
stdout
===== Step 0 | Position (1,1) =====
##########
#@.......#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 1 | Position (1,2) =====
##########
#.@......#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 2 | Position (1,3) =====
##########
#..@.....#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 3 | Position (1,4) =====
##########
#...@....#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 4 | Position (1,5) =====
##########
#....@...#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 5 | Position (1,6) =====
##########
#.....@..#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 6 | Position (1,7) =====
##########
#......@.#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 7 | Position (1,8) =====
##########
#.......@#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 8 | Position (2,8) =====
##########
#........#
#.######@#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 9 | Position (3,8) =====
##########
#........#
#.######.#
#......#@#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 10 | Position (4,8) =====
##########
#........#
#.######.#
#......#.#
###.##.#@#
#...#....#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 11 | Position (5,8) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#...@#
#.#.###..#
#.#.....##
#.#.E....#
##########

===== Step 12 | Position (6,8) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###.@#
#.#.....##
#.#.E....#
##########

===== Step 13 | Position (6,7) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###@.#
#.#.....##
#.#.E....#
##########

===== Step 14 | Position (7,7) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#....@##
#.#.E....#
##########

===== Step 15 | Position (8,7) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E..@.#
##########

===== Step 16 | Position (8,6) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E.@..#
##########

===== Step 17 | Position (8,5) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.E@...#
##########

===== Step 18 | Position (8,4) =====
##########
#........#
#.######.#
#......#.#
###.##.#.#
#...#....#
#.#.###..#
#.#.....##
#.#.@....#
##########

SPROBUJ JESZCZE RAZ