[解題報告][ZeroJudge][d626] 小畫家真好用

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
/*
Problem: d626
Language: C++
Result: AC (2ms, 706KB) on ZeroJudge
Author: m80126colin at 2010-07-13 16:55:33
Solution: Flood or DFS
*/
#include <iostream>
using namespace std;
int n;
bool ox[101][101],ox2[101][101];
inline void flood(int x,int y) {
if (ox[x][y]||ox2[x][y]) return;
ox2[x][y]=1;
if (x-1) flood(x-1,y);
if (y-1) flood(x,y-1);
if (x+1<=n) flood(x+1,y);
if (y+1<=n) flood(x,y+1);
}
int main() {
int i,j;
char ch;
scanf("%d\n",&n);
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++) {
ch=getchar();
while (ch=='\n'||ch==' ') ch=getchar();
ox[i][j]=ch=='+';
}
}
flood(1,1);
for (i=1;i<=n;i++) {
for (j=1;j<=n;j++) putchar((ox2[i][j]|ox[i][j]?'+':'-'));
puts("");
}
}
,