-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path352.cpp
More file actions
69 lines (46 loc) · 1.39 KB
/
352.cpp
File metadata and controls
69 lines (46 loc) · 1.39 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
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
/* The Seasonal War - 352 */
void eagles(int i,int j,char image[][28]){
image[i][j] = '0';
if(image[i-1][j-1] == '1')
eagles(i-1,j-1,image);
if(image[i-1][j] == '1')
eagles(i-1,j,image);
if(image[i-1][j+1] == '1')
eagles(i-1,j+1,image);
if(image[i][j-1] == '1')
eagles(i,j-1,image);
if(image[i][j] == '1')
eagles(i,j,image);
if(image[i][j+1] == '1')
eagles(i,j+1,image);
if(image[i+1][j-1] == '1')
eagles(i+1,j-1,image);
if(image[i+1][j] == '1')
eagles(i+1,j,image);
if(image[i+1][j+1] == '1')
eagles(i+1,j+1,image);
}
main(){
int c=0,e,i,j,n;
char aux[27][28],image[27][28];
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++)
scanf("%s",aux[i]);
for(i=0;i<=n+1;i++)
for(j=0;j<=n+1;j++)
image[i][j] = '\0';
for(i=0;i<n;i++)
for(j=0;j<=n;j++)
image[i+1][j+1] = aux[i][j];
e = 0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(image[i][j] == '1')
{
eagles(i,j,image);
e ++;
}
printf("Image number %d contains %d war eagles.\n",++c,e);
}
}