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<utility>
using namespace std;

int tile[21][21]={0};
int d[21][21]={0};
int lapse=0;
int W,H;
char a;
pair<int,int> person;
int answer=0;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

bool valid(int x,int y){
    return (x>=0 && x<H && y>=0 && y<W && tile[x][y]==1);
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

void dfs(int x,int y){
    ++answer;
    d[x][y]=1;
    //cout<<"visited ("<<x+1<<","<<y+1<<")\n";

    for(int i=0;i<4;++i){
        if(valid(x+dx[i],y+dy[i]) && d[x+dx[i]][y+dy[i]]==0){
            dfs(x+dx[i],y+dy[i]);
        }
    }
}

int main(){
    
    
    while(cin>>W>>H && W!=0){
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                cin>>a;
                if(a=='.'){
                    tile[i][j]=1;
                }
                else if(a=='@'){
                    person.first=i;
                    person.second=j;
                }
            }
        }

        dfs(person.first,person.second);

        cout<<answer<<"\n";
        answer=0;
        Fill(tile,0);
        Fill(d,0);
    }
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


int ans = 0;
void dfs(vector<vector<int> > &a, int x, int y){
	ans++;
	a[x][y] = 0;
	if(a[x-1][y]) dfs(a, x-1, y);
	if(a[x][y-1]) dfs(a, x, y-1);
	if(a[x+1][y]) dfs(a, x+1, y);
	if(a[x][y+1]) dfs(a, x, y+1);
//	return res;		//テ」ツ?ゥテ」ツ??」ツつ?」ツつ凝」ツつ禿」ツ??」ツつ催」ツ??」ツ??、ツサツ甘・ツコツヲ
}

bool solve(){

	while(1){
		ans = 0;
		
		int w,h;
		cin>> w>> h;
		if(w==0 && h==0) break;
		
		vector<vector<int> > a(h+2, vector<int> (w+2,0));
		complex<int> p;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char in;
				cin>> in;
				if(in == '#') a[i+1][j+1] = 0;
				if(in == '.') a[i+1][j+1] = 1;
				if(in == '@'){
					a[i+1][j+1] = 2;
					p.real() = i+1;
					p.imag() = j+1;
				}
			}
		}
/*		for(int i=0;i<h+2;i++){
			for(int j=0;j<w+2;j++){
				cout<< a[i][j];
			}
			cout<< endl;
		}
*/		
		dfs(a, p.real(), p.imag());
		
		cout<< ans<< endl;
	}
	
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int w,h;
char ba[20][20];

int const dx[] = {0,1,0,-1};
int const dy[] = {-1,0,1,0};
int go(int sx, int sy) {
  int ans = 0;
  REP(i,4) {
    int xx = sx+dx[i];
    int yy = sy+dy[i];
    if (xx<0||xx>=w||yy<0||yy>=h) continue;
    if (ba[xx][yy] == '.') {
      ba[xx][yy] = '#';
      ans++;
      ans += go(xx,yy);
    }
  }
  return ans;
}

int main() {
  while(cin >> w >> h, w+h) {
    int sx, sy;
    REP(y,h) {
      REP(x,w) {
        cin >> ba[x][y];
        if (ba[x][y]=='@') {
          sx = x;
          sy = y;
        }
      }
    }
    cout << go(sx,sy)+1 << endl;
    
  }
}

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;
typedef pair<int, int> pii;

int w, h;
int m[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int nw, int nh){
  REP(i, 4){
    if(nw + dx[i] < 0 or nw + dx[i] >= w or nh + dy[i] < 0 or nh + dy[i] >= h) continue;
    if(m[nw+dx[i]][nh+dy[i]] == 1) { m[nw+dx[i]][nh+dy[i]] = 2; dfs(nw+dx[i], nh+dy[i]); }
  }
  return;
}

int main(){
  while(cin >> w >> h and w + h){
    int sw, sh;
    REP(i, h){
      string str;
      cin >> str;
      REP(j, w) { m[j][i] = (str[j] == '#' ? -1 : 1); if(str[j] == '@') { sw = j; sh = i; m[j][i] = 2; } }
    }
    dfs(sw, sh);
    int res = 0;
    REP(i, h) REP(j, w) if(m[j][i] == 2) res++;
    cout << res << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

bool hoge(vector<string>& s) {
	int H = s.size(), W = s[0].size();
	bool flag = false;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++)
			if (s[y][x] == '.')
				for (int k = 0; k < 4; k++) {
					int _x = x + dx[k], _y = y + dy[k];
					if (_x >= 0 && _y >= 0 && _x < W && _y < H && s[_y][_x] == '@') {
						s[y][x] = '@';
						flag = true;
					}
				}
	return flag;
}

int main() {
	for (;;) {
		int W, H; cin >> W >> H;
		if (W == 0 && H == 0) break;
		vector<string> s(H);
		for (int i = 0; i < H; i++) cin >> s[i];
		while (hoge(s));
		int cnt = 0;
		for (int y = 0; y < H; y++)
			for (int x = 0; x < W; x++)
				if (s[y][x] == '@') cnt++;
		cout << cnt << endl;
	}
}