-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfalldown.cpp
More file actions
52 lines (48 loc) · 1.33 KB
/
Copy pathfalldown.cpp
File metadata and controls
52 lines (48 loc) · 1.33 KB
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
/*
Problem Name: Fall Down
Link to problem: https://codeforces.com/contest/1669/problem/G
*/
#include <bits/stdc++.h>
using namespace std;
bool checker(vector<vector<char>>& grid) {
bool finished_simulation = true;
for (int i = 0; i < (grid.size() - 1); i++) {
for (int j = 0; j < grid[0].size(); j++) {
if (grid[i][j] == '*' && grid[i + 1][j] == '.') {
swap(grid[i][j], grid[i + 1][j]);
finished_simulation = false;
}
}
}
return finished_simulation;
}
void dfs(vector<vector<char>>& grid) {
while (!checker(grid)) {
for (int i = 0; i < (grid.size() - 1); i++) {
for (int j = 0; j < grid[0].size(); j++) {
if (grid[i][j] == '*' && grid[i + 1][j] == '.') {
swap(grid[i][j], grid[i + 1][j]);
}
}
}
}
}
int main() {
int t, n, m; cin >> t;
while (t--) {
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
}
}
dfs(grid);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << grid[i][j];
}
cout << endl;
}
}
}