#include<iostream> #include<cstdio> using namespace std; char tiles[21][21]; int x,y,w,h,ans; int dx[4]={-1,0,0,1},dy[4]={0,-1,1,0};//^<> void dfs(int sx,int sy){ ans++;tiles[sy][sx]='#'; for(int i=0;i<4;i++){ int nx=sx+dx[i],ny=sy+dy[i]; if(nx>=1&&nx<=w&&ny>=1&&ny<=h&&tiles[ny][nx]=='.'/**/)dfs(nx,ny); } } int main(){ // freopen("red.txt","r",stdin); while(cin>>w>>h&&(w||h)){ ans=0; getchar(); for(int i=1;i<=h;i++){ for(int j=1;j<=w;j++){ tiles[i][j]=getchar(); if(tiles[i][j]=='@'){x=j;y=i;} } getchar(); } dfs(x,y); cout<<ans<<endl; } return 0; }
时间: 2024-11-02 23:42:45