Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

type Node struct {
	ID    int
	X, Y  int
	Color Color
	Nexts []*Node
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		// Initialize map
		m := map[int]map[int]*Node{}
		for x := 1; x <= w; x++ {
			m[x] = map[int]*Node{}
			for y := 1; y <= h; y++ {
				m[x][y] = &Node{ID: x + y*w, X: x, Y: y}
			}
		}
		for x := 1; x <= w; x++ {
			for y := 1; y <= h; y++ {
				nexts := []*Node{}
				if n, ok := m[x-1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y-1]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x+1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y+1]; ok {
					nexts = append(nexts, n)
				}
				m[x][y].Nexts = nexts
			}
		}

		// Set colors
		queue := []*Node{}
		touchedIDs := map[int]struct{}{}
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					n := m[i+1][y]
					n.Color = ColorBlack
					if c == '@' {
						queue = append(queue, n)
						touchedIDs[n.ID] = struct{}{}
					}
				case '#':
					m[i+1][y].Color = ColorRed
				}
			}
		}

		// Search
		visitedIDs := map[int]struct{}{}
		for {
			if len(queue) == 0 {
				break
			}
			n := queue[0]
			queue = queue[1:]
			visitedIDs[n.ID] = struct{}{}
			for _, next := range n.Nexts {
				if next.Color == ColorRed {
					continue
				}
				if _, ok := touchedIDs[next.ID]; !ok {
					queue = append(queue, next)
					touchedIDs[n.ID] = struct{}{}
				}
			}
		}
		fmt.Println(len(visitedIDs))
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;

int w,h;
char m[22][32];

int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
int dfs(int y,int x){
	if(m[y][x]=='#')return 0;
	int res=1;
	m[y][x]='#';
	for(int i=0;i<4;i++){
		res+=dfs(y+dy[i],x+dx[i]);
	}
	return res;
}
int main(){
	while(cin>>w>>h,w|h){
		memset(m,'#',sizeof(m));
		for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>m[i][j];
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(m[i][j]!='@')continue;
				cout<<dfs(i,j)<<endl;
				goto BREAK;
			}
		}
		BREAK:;
	}
	return 0;
}

C++: #include <cstdio>

char map[20][21];
int w, h;
int ans;
int x, y;
int xx, yy;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};

void Move(int X, int Y) {
	ans++;
	map[Y][X] = '#';
	for(int i = 0; i < 4; i++) {
		xx = X + dx[i];
		yy = Y + dy[i];
		if(0 <= xx && xx < w && 0 <= yy && yy < h && map[yy][xx] == '.') {
			Move(xx, yy);
		}
	}
}

int main(void) {
	while(1) {
		ans = 0;
		scanf("%d %d", &w, &h);
		if(!w && !h) break;
		for(int i = 0; i < h; i++) {
			scanf("%s", map[i]);
			for(int j = 0; j < w; j++) {
				if(map[i][j] == '@') {
					x = j;
					y = i;
				}
			}
		}
		Move(x, y);
		printf("%d\n", ans);
	}
	return 0;
}

C++: #include<cstdio>
#include<stack>

using namespace std;

struct Coord {
  int row;
  int col;
};

int solve (int W, int H);
  
int main () {
  int W, H;

  while(W!=0 && H!=0)
    {
      scanf("%d%d", &W, &H);
      if(W!=0 && H!=0)
	{
          printf("%d\n", solve(W,H));
	}
    }
}

int solve (int W, int H) {
  int n=0;
  char M[H+2][W+2];
  Coord start;
  for (int i=0; i<=W+1; i++) { M[0][i] = '#'; M[H+1][i] = '#'; }
  for (int i=1; i<=H; i++) { M[i][0] = '#'; M[i][W+1] = '#'; } 
  for (int i=1; i<=H; i++) {
    for (int j=1; j<=W; j++) {
      scanf(" %c", &M[i][j]);
      if (M[i][j]=='@') {
	start.row = i;
	start.col = j;
      }
    }
  }

  
  stack<Coord> S;
  S.push(start);
  while (!S.empty()) {
    Coord current = S.top(); S.pop();
    n++;
    int D1[]={1,0,-1,0}; int D2[]={0,-1,0,1};
    for (int d=0; d<4; d++) {
      Coord nc = current;
      nc.row += D1[d];
      nc.col += D2[d];
      if(M[nc.row][nc.col]!='#' && M[nc.row][nc.col]!='*' && M[nc.row][nc.col]!='@')
	{
	  M[nc.row][nc.col] = '*';
	  S.push(nc);
	}
    } 
    
  }
  return n;
}

C++: #include<iostream>
#include<queue>
using namespace std;
int W,H;
int m,n;
int counts;
struct test
{
    char c;
    int flag;
    int x;
    int y;
};
queue<test>Q;
int main()
{
    cin>>W>>H;
    while(W!=0 && H!=0)
    {
        counts=0;
        test A[H][W];
        for(int i=0;i<H;i++)
            for(int j=0;j<W;j++)
            {
                cin>>A[i][j].c;
                A[i][j].flag=0;
                A[i][j].x=i;
                A[i][j].y=j;
                if(A[i][j].c=='@')
                {
                    m=i;
                    n=j;
                }
            }
        Q.push(A[m][n]);
        counts++;
        A[m][n].flag=1;
        while(!Q.empty())
        {
            test p=Q.front();
            if(p.x-1>=0 && p.y>=0 && p.x-1<H && p.y<W && A[p.x-1][p.y].c=='.' && A[p.x-1][p.y].flag==0)
            {
                Q.push(A[p.x-1][p.y]);
                A[p.x-1][p.y].flag=1;
                counts++;
            }
            if(p.x>=0 && p.y-1>=0 && p.x<H && p.y-1<W && A[p.x][p.y-1].c=='.' && A[p.x][p.y-1].flag==0)
            {
                Q.push(A[p.x][p.y-1]);
                A[p.x][p.y-1].flag=1;
                counts++;
            }
            if(p.x+1>=0 && p.y>=0 && p.x+1<H && p.y<W && A[p.x+1][p.y].c=='.' && A[p.x+1][p.y].flag==0)
            {
                Q.push(A[p.x+1][p.y]);
                A[p.x+1][p.y].flag=1;
                counts++;
            }
            if(p.x>=0 && p.y+1>=0 && p.x<H && p.y+1<W && A[p.x][p.y+1].c=='.' && A[p.x][p.y+1].flag==0)
            {
                Q.push(A[p.x][p.y+1]);
                A[p.x][p.y+1].flag=1;
                counts++;
            }
            Q.pop();
        }
        cout<<counts<<endl;
        cin>>W>>H;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
char cm[200][200];
int im[200][200];
 int W,H;
bool visited[200][200];
int sy,sx;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
typedef pair<int,int> P;

int bfs();

int main(){
 

  while(1)
    {
      cin >> W >> H;
      if(W == 0 && H == 0)break;
      memset(im,0,sizeof(im));
      memset(visited,false,sizeof(visited));
      for(int i=0;i<H;i++)
	{
	  for(int j=0;j<W;j++)
	    {
	      cin >> cm[i][j];
	      if(cm[i][j] == '#'){
		im[i][j] = 8;
	      }
	      else if(cm[i][j] == '@')
		{
		  sy = i;
		  sx = j;
		}
	    }
	}

      cout << bfs() << endl;
      /*     
 for(int i=0;i<H;i++){
	for(int j=0;j<W;j++)cout << im[i][j];
	cout << endl;
      }
      */

    }
}

int bfs()
{
  int maxx = 0;
  queue<P> que;
  que.push(P(sx,sy)); 
  im[sy][sx] = 1;
  int cou=1;
  visited[sy][sx] = true;

  while(que.size())
    {
      P p = que.front();
      que.pop();

      for(int i=0;i<4;i++)
	{
	  int nx = p.first + dx[i],ny = p.second + dy[i];

	  if(0 <= nx && nx < W && 0 <= ny && ny < H && cm[ny][nx] != '#' && !visited[ny][nx])
	    {
	      visited[ny][nx] = true;
	      cou++;
	      im[ny][nx]=cou;
	      maxx = max(maxx,im[ny][nx]);
	      que.push(P(nx,ny));
	    }
	}
      
    }
return maxx;
}