-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoj1130.cpp
More file actions
57 lines (46 loc) · 1.04 KB
/
aoj1130.cpp
File metadata and controls
57 lines (46 loc) · 1.04 KB
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
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int H, W;
int table[20][20];
int cnt;
void calc(int current_y, int current_x) {
table[current_y][current_x] = 3;
if(current_y > 0 && table[current_y-1][current_x] == 1)
calc(current_y-1, current_x);
if(current_x > 0 && table[current_y][current_x-1] == 1)
calc(current_y, current_x-1);
if(current_y < H-1 && table[current_y+1][current_x] == 1)
calc(current_y+1, current_x);
if(current_x < W-1 && table[current_y][current_x+1] == 1)
calc(current_y, current_x+1);
cnt++;
}
int main() {
while(1) {
cnt = 0;
cin >> W >> H;
if(W == 0 && H == 0) break;
char temp;
int current[2];
for(int i=0; i<H; i++) {
for(int j=0; j<W; j++) {
cin >> temp;
if(temp=='.') table[i][j] = 1;
else if(temp=='#') table[i][j] = 2;
else if(temp=='@') {
table[i][j] = 0;
current[0] = i;
current[1] = j;
}
}
}
calc(current[0], current[1]);
cout << cnt << endl;
}
return 0;
}