#include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <cmath> using namespace std; int height, width, last1, last2, n_moves; char board[500][500]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> height >> width; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) cin >> board[i][j]; cin >> n_moves; for (int i = 0; i < n_moves; i++) { char a; cin >> a; switch (a) { case 'G': last1 = 1; break; case 'D': last1 = 2; break; case 'L': last2 = 1; break; case 'P': last2 = 2; break; } } if (last1 == 1) { for (int j = 0; j < width; j++) { vector <char> row; for (int i = 0; i < height; i++) if (board[i][j] != '.') row.push_back(board[i][j]); for (int i = 0; i < height; i++) board[i][j] = (i < row.size()) ? row[i] : '.'; } } if (last1 == 2) { for (int j = 0; j < width; j++) { vector <char> row; for (int i = height - 1; i >= 0; i--) if (board[i][j] != '.') row.push_back(board[i][j]); for (int i = 0; i < height; i++) board[height - i - 1][j] = (i < row.size()) ? row[i] : '.'; } } if (last2 == 1) { for (int i = 0; i < height; i++) { vector <char> row; for (int j = 0; j < width; j++) if (board[i][j] != '.') row.push_back(board[i][j]); for (int j = 0; j < width; j++) board[i][j] = (j < row.size()) ? row[j] : '.'; } } if (last2 == 2) { for (int i = 0; i < height; i++) { vector <char> row; for (int j = width - 1; j >= 0; j--) if (board[i][j] != '.') row.push_back(board[i][j]); for (int j = 0; j < width; j++) board[i][width - j - 1] = (j < row.size()) ? row[j] : '.'; } } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) cout << board[i][j]; cout << '\n'; } }
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 | #include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> #include <map> #include <set> #include <stack> #include <cmath> using namespace std; int height, width, last1, last2, n_moves; char board[500][500]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> height >> width; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) cin >> board[i][j]; cin >> n_moves; for (int i = 0; i < n_moves; i++) { char a; cin >> a; switch (a) { case 'G': last1 = 1; break; case 'D': last1 = 2; break; case 'L': last2 = 1; break; case 'P': last2 = 2; break; } } if (last1 == 1) { for (int j = 0; j < width; j++) { vector <char> row; for (int i = 0; i < height; i++) if (board[i][j] != '.') row.push_back(board[i][j]); for (int i = 0; i < height; i++) board[i][j] = (i < row.size()) ? row[i] : '.'; } } if (last1 == 2) { for (int j = 0; j < width; j++) { vector <char> row; for (int i = height - 1; i >= 0; i--) if (board[i][j] != '.') row.push_back(board[i][j]); for (int i = 0; i < height; i++) board[height - i - 1][j] = (i < row.size()) ? row[i] : '.'; } } if (last2 == 1) { for (int i = 0; i < height; i++) { vector <char> row; for (int j = 0; j < width; j++) if (board[i][j] != '.') row.push_back(board[i][j]); for (int j = 0; j < width; j++) board[i][j] = (j < row.size()) ? row[j] : '.'; } } if (last2 == 2) { for (int i = 0; i < height; i++) { vector <char> row; for (int j = width - 1; j >= 0; j--) if (board[i][j] != '.') row.push_back(board[i][j]); for (int j = 0; j < width; j++) board[i][width - j - 1] = (j < row.size()) ? row[j] : '.'; } } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) cout << board[i][j]; cout << '\n'; } } |