// Kacper Orszulak #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pss = pair<size_t, size_t>; #define st first #define nd second #define fft(n) for (size_t i = 0; i < n; ++i) // Fast For Transform constexpr int INF = 1e9+7; // Pulling to y = 0 // char c = access(y, x) void side_operation( const function<char&(int, int)> &access, int max_y, int max_x) { for (int x = 0; x < max_x; ++x) { int fill_y = 0, search_y = 0; while (search_y < max_y) { char &c = access(search_y++, x); if (c != '.') { if (fill_y+1 != search_y) access(fill_y, x) = c, c = '.'; ++fill_y; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int dim_y, dim_x; cin >> dim_y >> dim_x; vector<string> grid(dim_y); for (string &s : grid) cin >> s; const auto pull_up_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[y][x]; }; const auto pull_down_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[dim_y-1 -y][x]; }; const auto pull_left_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[x][y]; }; const auto pull_right_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[x][dim_x-1 -y]; }; int k; cin >> k; string operations; cin >> operations; for (const char op : operations) { if (op == 'G') { side_operation(pull_up_access, dim_y, dim_x); } else if (op == 'D') { side_operation(pull_down_access, dim_y, dim_x); } else if (op == 'L') { side_operation(pull_left_access, dim_x, dim_y); } else if (op == 'P') { side_operation(pull_right_access, dim_x, dim_y); } } for (const string &s : grid) cout << s << '\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 | // Kacper Orszulak #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pss = pair<size_t, size_t>; #define st first #define nd second #define fft(n) for (size_t i = 0; i < n; ++i) // Fast For Transform constexpr int INF = 1e9+7; // Pulling to y = 0 // char c = access(y, x) void side_operation( const function<char&(int, int)> &access, int max_y, int max_x) { for (int x = 0; x < max_x; ++x) { int fill_y = 0, search_y = 0; while (search_y < max_y) { char &c = access(search_y++, x); if (c != '.') { if (fill_y+1 != search_y) access(fill_y, x) = c, c = '.'; ++fill_y; } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int dim_y, dim_x; cin >> dim_y >> dim_x; vector<string> grid(dim_y); for (string &s : grid) cin >> s; const auto pull_up_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[y][x]; }; const auto pull_down_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[dim_y-1 -y][x]; }; const auto pull_left_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[x][y]; }; const auto pull_right_access = [&grid, &dim_y, &dim_x] (int y, int x) -> char& { return grid[x][dim_x-1 -y]; }; int k; cin >> k; string operations; cin >> operations; for (const char op : operations) { if (op == 'G') { side_operation(pull_up_access, dim_y, dim_x); } else if (op == 'D') { side_operation(pull_down_access, dim_y, dim_x); } else if (op == 'L') { side_operation(pull_left_access, dim_x, dim_y); } else if (op == 'P') { side_operation(pull_right_access, dim_x, dim_y); } } for (const string &s : grid) cout << s << '\n'; } |