Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- char arr[3000][3000]; int a, b; char all[3000][3000];
- bool car()
- {
- for (int i = 0; i < a-1; i++)
- {
- for (int j = 0; j < b; j++)
- {
- if (arr[i][j] == 'X')
- {
- if (arr[i+1][j] == '#')
- return false;
- }
- }
- }
- return true;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin >> a >> b;
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- cin >> arr[i][j];
- }
- }
- int k = 0;
- while (car())
- {
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- if (i == 0 && k == 0)
- all[i][j] = '.';
- else if (arr[i][j] != '#')
- all[i][j] = arr[i-1][j];
- else if (arr[i][j] == '#')
- all[i][j] = '#';
- else if (i == a-1 && k == 0)
- {
- all[i][j] = '#'; k++;
- }
- }
- }
- memcpy(arr, all, sizeof(arr));
- }
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < b; j++)
- {
- cout << arr[i][j];
- }
- if (i != a-1)
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement