| ||||||||||
| 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 | |||||||||
怎么wa,谢谢啊#include<iostream>
using namespace std;
int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
char str[25][25];
int m,n;
int count;
bool Isok(int a,int b)
{
if(a<0||b<0||a>n||b>m)
return false;
return true;
}
void DFS(int i,int j)
{
count++;
str[i][j]='#';
for(int k=0;k<4;k++)
{
int x=i+dir[k][0];
int y=j+dir[k][1];
if(Isok(x,y)==true&&str[x][y]=='.')
{
DFS(x,y);
}
}
}
int main()
{
int i,j;
while(scanf("%d%d",&m,&n)==2)
{
if(m+n==0) break;
count=0;
for(i=0;i<n;i++)
scanf("%s",str[i]);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
if(str[i][j]=='@')
{
DFS(i,j);
break;
}
printf("%d\n",count);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator