-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path784.cpp
51 lines (44 loc) · 1.12 KB
/
784.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
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
size_t width = 81;
char * land[31];
void paint(int x, int y)
{
land[x][y] = '#';
if (land[x + 1][y] == ' ') paint(x + 1, y);
if (land[x - 1][y] == ' ') paint(x - 1, y);
if (land[x][y + 1] == ' ') paint(x, y + 1);
if (land[x][y - 1] == ' ') paint(x, y - 1);
}
int main(void)
{
for (int i = 0; i < 31; ++i)
land[i] = (char *)malloc(sizeof(char) * width);
bool found;
int T, x, y, n;
scanf("%d\n", &T);
while (T--) {
n = 0;
found = false;
while (1) {
getline(&land[n], &width, stdin);
if (land[n][0] == '_') break;
if (!found) {
for (int i = 1; i < strlen(land[n]) - 1; ++i)
if (land[n][i] == '*') {
found = true;
x = n;
y = i;
}
}
++n;
}
paint(x, y);
for (int i = 0; i < n; ++i)
printf("%s", land[i]);
printf("%s", land[n]);
}
return 0;
}