-
Notifications
You must be signed in to change notification settings - Fork 0
/
00469.cpp
60 lines (56 loc) · 1.19 KB
/
00469.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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char arr[110][110];
int w,h,ans,dr[8] = {-1,0,1,0,1,1,-1,-1},dc[8] = {0,-1,0,1,1,-1,1,-1};
void play(int r,int c)
{
arr[r][c] = 'V';
ans++;
int i;
for(i = 0;i < 8;i++)
{
if(arr[r+dr[i]][c+dc[i]] == 'W' && r+dr[i] < h && r+dr[i] >= 0 && c+dc[i] < w && c+dc[i] >= 0)
play(r+dr[i],c+dc[i]);
}
}
int main()
{
char str[110],*p;
int q,i,j,r,c;
scanf("%d ",&q);
while(q--)
{
i = 0;
do
{
gets(str);
}while(!strlen(str));
w = strlen(str);
while(isalpha(str[0]))
{
strcpy(arr[i++],str);
gets(str);
}
h = i;
do
{
sscanf(str,"%d %d",&r,&c);
ans = 0;
play(r-1,c-1);
printf("%d\n",ans);
for(i = 0;i < h;i++)
{
for(j = 0;j < w;j++)
{
if(arr[i][j] == 'V')
arr[i][j] = 'W';
}
}
p = gets(str);
}while(strcmp(str,"") && p != NULL);
if(q)
printf("\n");
}
return 0;
}