#include<bits/stdc++.h>
using namespace std;
char a[507][507];
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0 ; i < n; ++i)
for(int j = 0; j < m; ++j)
cin >> a[i][j];
int k;
cin >> k;
string moves;
cin >> moves;
for(auto& it: moves)
{
if(it == 'G')
{
for(int col = 0; col < m; ++col)
{
int first_empty = 0;
for(int row = 0; row < n; ++row)
{
if(a[row][col] != '.')
{
swap(a[row][col], a[first_empty][col]);
++first_empty;
}
}
}
}
else if(it == 'D')
{
for(int col = 0; col < m; ++col)
{
int first_empty = n - 1;
for(int row = n - 1; row >= 0; --row)
{
if(a[row][col] != '.')
{
swap(a[row][col], a[first_empty][col]);
--first_empty;
}
}
}
}
else if(it == 'L')
{
for(int row = 0; row < n; ++row)
{
int first_empty = 0;
for(int col = 0; col < m; ++col)
{
if(a[row][col] != '.')
{
swap(a[row][col], a[row][first_empty]);
++first_empty;
}
}
}
}
else if(it == 'P')
{
for(int row = 0; row < n; ++row)
{
int first_empty = m - 1;
for(int col = m - 1; col >= 0; --col)
{
if(a[row][col] != '.')
{
swap(a[row][col], a[row][first_empty]);
--first_empty;
}
}
}
}
}
for(int i = 0 ; i < n; ++i)
{
for(int j = 0; j < m; ++j)
{
cout << a[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 | #include<bits/stdc++.h> using namespace std; char a[507][507]; int main() { int n, m; cin >> n >> m; for(int i = 0 ; i < n; ++i) for(int j = 0; j < m; ++j) cin >> a[i][j]; int k; cin >> k; string moves; cin >> moves; for(auto& it: moves) { if(it == 'G') { for(int col = 0; col < m; ++col) { int first_empty = 0; for(int row = 0; row < n; ++row) { if(a[row][col] != '.') { swap(a[row][col], a[first_empty][col]); ++first_empty; } } } } else if(it == 'D') { for(int col = 0; col < m; ++col) { int first_empty = n - 1; for(int row = n - 1; row >= 0; --row) { if(a[row][col] != '.') { swap(a[row][col], a[first_empty][col]); --first_empty; } } } } else if(it == 'L') { for(int row = 0; row < n; ++row) { int first_empty = 0; for(int col = 0; col < m; ++col) { if(a[row][col] != '.') { swap(a[row][col], a[row][first_empty]); ++first_empty; } } } } else if(it == 'P') { for(int row = 0; row < n; ++row) { int first_empty = m - 1; for(int col = m - 1; col >= 0; --col) { if(a[row][col] != '.') { swap(a[row][col], a[row][first_empty]); --first_empty; } } } } } for(int i = 0 ; i < n; ++i) { for(int j = 0; j < m; ++j) { cout << a[i][j]; } cout << "\n"; } } |
English