forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrings2.cpp
70 lines (61 loc) · 1.8 KB
/
rings2.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
int main() {
int height, width;
cin >> height >> width;
char tree[150][150];
for(int i = 0; i < 103; i++) {
for(int j = 0; j < 103; j++) {
tree[i][j] = '.';
}
}
for(int i = 1; i <= height; i++) {
for(int j = 1; j <= width; j++) {
cin >> tree[i][j];
}
}
bool swapMade = true;
int k = 0;
while(swapMade) {
k++;
swapMade = false;
for(int i = 1; i <= height; i++)
{
for(int j = 1; j <= width; j++)
{
if(tree[i][j] == 'T' && (tree[i-1][j] == '.' || tree[i+1][j] == '.' || tree[i][j-1] == '.' || tree[i][j+1] == '.')) {
tree[i][j] = k + '0';
swapMade = true;
}
if(tree[i][j] == 'T' && (tree[i-1][j] == k + '0' - 1 || tree[i+1][j] == k + '0' - 1 || tree[i][j-1] == k + '0' - 1 || tree[i][j+1] == k + '0' - 1)) {
tree[i][j] = k + '0';
swapMade = true;
}
}
}
}
for(int i = 1; i <= height; i++) {
for(int j = 1; j <= width; j++) {
if(k < 10) {
if(tree[i][j] == '.') {
cout << "..";
}
else {
cout << '.' << int(tree[i][j] - '0');
}
}
else {
if(tree[i][j] == '.') {
cout << "...";
}
else {
if(int(tree[i][j] - '0') >= 10)
cout << '.' << int(tree[i][j] - '0');
else
cout << ".." << int(tree[i][j] - '0');
}
}
}
cout << '\n';
}
}