#include<bits/stdc++.h>
#define MAX 1111
using namespace std;
int cnt=0,vis[101][101],n,i;
char s1[101][101],s[101];
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
int dfs(int r,int c)
{
cnt++;
vis[r][c]=1;
int x1,y1,i1;
for(i1=0;i1<8;i1++)
{
x1=r+dx[i1];
y1=c+dy[i1];
if((x1>=0&&x1<i)&&(y1>=0&&y1<n)&&(vis[x1][y1]==0)&&(s1[x1][y1]=='W'))
{
vis[x1][y1]=1;
dfs(x1,y1);
}
}
return cnt;
}
main()
{
int ts,cs=1;
cin>>ts;
getchar();
getchar();
while(ts--)
{
if(cs!=1)
cout<<endl;
cs++;
i=0;
n=0;
while(gets(s)&&strlen(s)>0)
{
if(s[0]=='L'||s[0]=='W')
{
strcpy(s1[i],s);
i++;
n=strlen(s);
}
else
{
int row,col;
sscanf(s, "%d %d", &row, &col);
cnt=0;
cnt=dfs(row-1,col-1);
cout<<cnt<<endl;
memset(vis,0,sizeof(vis));
}
}
}
}
#define MAX 1111
using namespace std;
int cnt=0,vis[101][101],n,i;
char s1[101][101],s[101];
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
int dfs(int r,int c)
{
cnt++;
vis[r][c]=1;
int x1,y1,i1;
for(i1=0;i1<8;i1++)
{
x1=r+dx[i1];
y1=c+dy[i1];
if((x1>=0&&x1<i)&&(y1>=0&&y1<n)&&(vis[x1][y1]==0)&&(s1[x1][y1]=='W'))
{
vis[x1][y1]=1;
dfs(x1,y1);
}
}
return cnt;
}
main()
{
int ts,cs=1;
cin>>ts;
getchar();
getchar();
while(ts--)
{
if(cs!=1)
cout<<endl;
cs++;
i=0;
n=0;
while(gets(s)&&strlen(s)>0)
{
if(s[0]=='L'||s[0]=='W')
{
strcpy(s1[i],s);
i++;
n=strlen(s);
}
else
{
int row,col;
sscanf(s, "%d %d", &row, &col);
cnt=0;
cnt=dfs(row-1,col-1);
cout<<cnt<<endl;
memset(vis,0,sizeof(vis));
}
}
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন