-
Notifications
You must be signed in to change notification settings - Fork 0
/
3052.cpp
49 lines (43 loc) · 1.11 KB
/
3052.cpp
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<string> c(n+2, string(m+2, '#'));
c[n+1] = string(m+2, '.');
for (int i = 1; i <= n; i++)
{
string row;
cin >> row;
for(int j = 1; j <= m; j++)
c[i][j] = row[j-1];
}
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(c[i][j] == '.')
{
if(c[i-1][j] == 'o') c[i][j] = 'o';
if(c[i][j-1] == 'o' && c[i+1][j-1] == '#') c[i][j] = 'o';
if(c[i][j+1] == 'o' && c[i+1][j+1] == '#') c[i][j] = 'o';
}
}
for(int j = m; j > 0; j--)
{
if(c[i][j] == '.')
{
if(c[i-1][j] == 'o') c[i][j] = 'o';
if(c[i][j-1] == 'o' && c[i+1][j-1] == '#') c[i][j] = 'o';
if(c[i][j+1] == 'o' && c[i+1][j+1] == '#') c[i][j] = 'o';
}
}
}
for (int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
cout << c[i][j];
cout << endl;
}
}