| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
终于AC了,庆祝一下#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void solution(char str[][103],int i,int j)
{
if(str[i][j]=='W')
{
str[i][j]='.';
solution(str,i-1,j-1);
solution(str,i-1,j);
solution(str,i-1,j+1);
solution(str,i,j+1);
solution(str,i,j-1);
solution(str,i+1,j-1);
solution(str,i+1,j);
solution(str,i+1,j+1);
}
return ;
}
int main()
{
int i,j,temp,m,n;
char str[102][103],k;
while(scanf("%d %d",&m,&n)!=EOF)
{
if(m==0) break;
else
{
temp=0;
for(i=0;i<m+2;i++)
for(j=0;j<n+2;j++)
str[i][j]='.';
for(i=1;i<m+1;i++)
{
scanf("%s",str[i]+1);
str[i][n+1]='.';
}
for(i=1;i<m+1;i++)
{
for(j=1;j<n+1;j++)
{
if(str[i][j]=='W')
{
temp++;
solution(str,i,j);
}
}
}
printf("%d\n",temp);
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator