#include <iostream> #include <vector> #include <string> using namespace std; typedef int ll; class vector2ll { public: ll X, Y; }; int main() { vector2ll BoardS{}; cin >> BoardS.Y >> BoardS.X; vector<vector<char>> Board; Board.resize(BoardS.Y); for (int y = 0; y < BoardS.Y; y++) { Board[y].resize(BoardS.X); for (int x = 0; x < BoardS.X; x++) cin >> Board[y][x]; } string Turn; cin >> Turn >> Turn; string Position; for (ll c = 0; c < Turn.size(); c++) { if (Turn[c - 1] == Turn[c]) break; switch (Turn[c]) { case 'L': for (ll y = 0; y < BoardS.Y; y++) { ll iX = 0; for (ll x = 0; x < BoardS.X; x++) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[y][iX] = Board[y][x]; if (iX != x) Board[y][x] = '.'; iX++; } } break; case 'P': for (ll y = 0; y < BoardS.Y; y++) { ll iX = BoardS.X - 1; for (ll x = BoardS.X - 1; x >= 0; x--) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[y][iX] = Board[y][x]; if (iX != x) Board[y][x] = '.'; iX--; } } break; case 'G': for (ll x = 0; x < BoardS.X; x++) { ll iY = 0; for (ll y = 0; y < BoardS.Y; y++) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[iY][x] = Board[y][x]; if (iY != y) Board[y][x] = '.'; iY++; } } break; case 'D': for (ll x = 0; x < BoardS.X; x++) { ll iY = BoardS.Y - 1; for (ll y = BoardS.Y - 1; y >= 0; y--) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[iY][x] = Board[y][x]; if (iY != y) Board[y][x] = '.'; iY--; } } default: break; } } for (ll y = 0; y < BoardS.Y; y++) { for (ll x = 0; x < BoardS.X; x++) cout << Board[y][x]; cout << "\n"; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | #include <iostream> #include <vector> #include <string> using namespace std; typedef int ll; class vector2ll { public: ll X, Y; }; int main() { vector2ll BoardS{}; cin >> BoardS.Y >> BoardS.X; vector<vector<char>> Board; Board.resize(BoardS.Y); for (int y = 0; y < BoardS.Y; y++) { Board[y].resize(BoardS.X); for (int x = 0; x < BoardS.X; x++) cin >> Board[y][x]; } string Turn; cin >> Turn >> Turn; string Position; for (ll c = 0; c < Turn.size(); c++) { if (Turn[c - 1] == Turn[c]) break; switch (Turn[c]) { case 'L': for (ll y = 0; y < BoardS.Y; y++) { ll iX = 0; for (ll x = 0; x < BoardS.X; x++) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[y][iX] = Board[y][x]; if (iX != x) Board[y][x] = '.'; iX++; } } break; case 'P': for (ll y = 0; y < BoardS.Y; y++) { ll iX = BoardS.X - 1; for (ll x = BoardS.X - 1; x >= 0; x--) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[y][iX] = Board[y][x]; if (iX != x) Board[y][x] = '.'; iX--; } } break; case 'G': for (ll x = 0; x < BoardS.X; x++) { ll iY = 0; for (ll y = 0; y < BoardS.Y; y++) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[iY][x] = Board[y][x]; if (iY != y) Board[y][x] = '.'; iY++; } } break; case 'D': for (ll x = 0; x < BoardS.X; x++) { ll iY = BoardS.Y - 1; for (ll y = BoardS.Y - 1; y >= 0; y--) if (Board[y][x] == 'B' || Board[y][x] == 'C') { Board[iY][x] = Board[y][x]; if (iY != y) Board[y][x] = '.'; iY--; } } default: break; } } for (ll y = 0; y < BoardS.Y; y++) { for (ll x = 0; x < BoardS.X; x++) cout << Board[y][x]; cout << "\n"; } return 0; } |