-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP784.cpp
69 lines (60 loc) · 1.29 KB
/
P784.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>
#include <stdio.h>
#include <stack>
typedef std::pair<int,int> Point;
#define X first
#define Y second
#define WIDTH 83
typedef std::stack<Point> Stack;
void die() {
int *a = NULL;
a[5] = 6;
}
int main() {
char c, w[WIDTH*32];
int cases = 0;
gets(w);
for(int i = 0; isdigit(c = w[i]); ++i)
cases = 10*cases + (c-'0');
for(int cas = 0; cas < cases; ++cas) {
int lines = 0;
bool foundStart = false;
Point start;
do {
gets(&w[WIDTH*lines]);
if(!foundStart) {
for(int i = 1; isprint(c = w[WIDTH*lines+i]); ++i) {
if(c == '*') {
start = Point(i, lines);
foundStart = true;
w[WIDTH*lines+i] = ' ';
break;
}
}
}
++lines;
}
while(w[WIDTH*(lines-1)] != '_');
if(!foundStart)
die();
Stack s;
s.push(start);
while(!s.empty()) {
Point p = s.top(); s.pop();
if(w[WIDTH*p.Y+p.X] != ' ')
continue;
w[WIDTH*p.Y+p.X] = '#';
if(w[WIDTH*p.Y+p.X-1] == ' ')
s.push(Point(p.X-1, p.Y));
if(w[WIDTH*(p.Y-1)+p.X] == ' ')
s.push(Point(p.X, p.Y-1));
if(w[WIDTH*p.Y+p.X+1] == ' ')
s.push(Point(p.X+1, p.Y));
if(w[WIDTH*(p.Y+1)+p.X] == ' ')
s.push(Point(p.X, p.Y+1));
}
for(int i = 0; i < lines; ++i)
puts(&w[WIDTH*i]);
}
return 0;
}