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++: //00
#include<iostream>
#include<queue>
#include<utility>

using namespace std;

int main(){
  for(int W,H;cin>>W>>H,W|H;){
    bool g[20][20];
    queue<pair<int,int> > que;
    for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
	char c;
	cin>>c;
	g[y][x]=c=='.';
	if(c=='@'){
	  que.push(make_pair(y,x));
	}
      }
    }
    int ans=0;
    while(!que.empty()){
      ans++;
      int y=que.front().first;
      int x=que.front().second;
      que.pop();
      int dy[]={0,1,0,-1};
      int dx[]={1,0,-1,0};
      for(int i=0;i<4;i++){
	int ny=y+dy[i];
	int nx=x+dx[i];
	if(0<=ny&&ny<H&&0<=nx&&nx<W&&g[ny][nx]){
	  que.push(make_pair(ny,nx));
	  g[ny][nx]=false;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int dfs(int x,int y,int f[32][32]) {
	int n = 1;
	f[x][y] = 0;
	if (f[x + 1][y] == 1)
		n += dfs(x + 1, y, f);
	if (f[x - 1][y] == 1)
		n += dfs(x - 1, y, f);
	if (f[x][y + 1] == 1)
		n += dfs(x, y + 1, f);
	if (f[x][y - 1] == 1)
		n += dfs(x, y - 1, f);
	return n;
}


int main()
{
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0 && h == 0)break;
		int floor[32][32] = {};
		int startX = 0;
		int startY = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				char c;
				cin >> c;
				if (c == '.' || c == '@') {
					floor[i][j] = 1;
					if (c == '@') {
						startX = i;
						startY = j;
					}
				}
				else if (c == '#')floor[i][j] = 0;
			}
		}
		int cnt = dfs(startX, startY, floor);
		cout << cnt << endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int dx[] = { -1, 0, 1, 0};
int dy[] = { 0, 1, 0, -1};

int dfs(vector< vector<bool> > &m, int x, int y){
	if(!m[x][y])return 0;
	int ret = 1;
	m[x][y] = false;
	for(int i = 0; i < 4; i++){
		ret += dfs(m, x+dx[i], y+dy[i]);
	}
	return ret;
}

int main(){
	while(true){
		int h,w; cin >> w >> h;
		if(h == 0)break;
		pair<int,int> s;
		vector< vector<bool> > m(h+2, vector<bool>(w+2, false));
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				char c; cin >> c;
				if( c == '.'){
					m[i+1][j+1] = true;
				}
				else if( c == '@'){
					m[i+1][j+1] = true;
					s = make_pair(i+1, j+1);
				}
			}
		}
		int ans = dfs(m,s.first, s.second);
		cout << ans << endl;
	}
	return 0;
}

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

typedef pair<int, int> pxy;

char map[20][20];

int W, H, start_x, start_y, ans = 0;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

void dfs(int sx, int sy)
{
  stack<pxy> s;
  s.push(pxy(sx, sy));
  while(!s.empty()){
    int x, y;
    x = s.top().first;
    y = s.top().second;
    s.pop();
    if(map[x][y] != '#'){
      ans++;
      map[x][y] = '#';
      for(int i = 0; i < 4; i++){
	int next_x = x + dx[i], next_y = y + dy[i];
	if(next_x < W && next_x >= 0 && next_y < H && next_y >= 0){
	  s.push(pxy(next_x, next_y));
	}
      }
    }
  }
}

int main()
{
  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0){
      break;
    }else{
      for(int i = 0; i < H; i++){
	for(int j = 0; j < W; j++){
	  cin >> map[j][i];
	  if(map[j][i] == '@'){
	    start_x = j;
	    start_y = i;
	  }
	}
      }
      dfs(start_x, start_y);
      cout << ans << endl;
      ans = 0;
    }
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
 
int w, h;
 
int dfs(int y, int x, vector<string> &v){
  int my[] = {-1,0,1,0};
  int mx[] = {0,-1,0,1};
  int ret = 1;
  REP(i, 4){
    int ny = y + my[i], nx = x + mx[i];
    if(0<=ny&&ny<h&&0<=nx&&nx<w && v[ny][nx] == '.'){
      v[ny][nx] = '#';
      ret += dfs(ny, nx, v);
    }
  }
  return ret;
}
 
int main(){
  while(cin >>w >>h && w){
    vector<string> v(h);
    REP(i, h) cin >>v[i];
    REP(i, h) REP(j, w) if(v[i][j] == '@') cout <<dfs(i, j, v) <<endl;
  }
  return 0;
}