-
Notifications
You must be signed in to change notification settings - Fork 0
/
572.cpp
74 lines (49 loc) · 1.43 KB
/
572.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
70
71
72
73
74
#include<stdio.h>
/* Oil Deposits - 572 */
void eagles(int i,int j,char image[][103]){
image[i][j] = '*';
if(image[i-1][j-1] == '@')
eagles(i-1,j-1,image);
if(image[i-1][j] == '@')
eagles(i-1,j,image);
if(image[i-1][j+1] == '@')
eagles(i-1,j+1,image);
if(image[i][j-1] == '@')
eagles(i,j-1,image);
if(image[i][j] == '@')
eagles(i,j,image);
if(image[i][j+1] == '@')
eagles(i,j+1,image);
if(image[i+1][j-1] == '@')
eagles(i+1,j-1,image);
if(image[i+1][j] == '@')
eagles(i+1,j,image);
if(image[i+1][j+1] == '@')
eagles(i+1,j+1,image);
}
main(){
int i,j,m,n,oil;
char aux[102][103],image[102][103];
while(1){
scanf("%d %d",&m,&n);
if(m == 0)
break;
for(i=0;i<m;i++)
scanf("%s",aux[i]);
for(i=0;i<=m+1;i++)
for(j=0;j<=n+1;j++)
image[i][j] = '\0';
for(i=0;i<=m;i++)
for(j=0;j<=n;j++)
image[i+1][j+1] = aux[i][j];
oil = 0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(image[i][j] == '@')
{
eagles(i,j,image);
oil ++;
}
printf("%d\n",oil);
}
}