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 <cstdio>


char board[20][20] = {};
int W, H;

int count(int x, int y) {
	if (board[x][y] == '#') return 0;
	if (x < 0 || W <= x) return 0;
	if (y < 0 || H <= y) return 0;

	board[x][y] = '#';

	return 1 +
		count(x - 1, y) +
		count(x + 1, y) +
		count(x, y - 1) +
		count(x, y + 1);
}

int main() {
	while (true) {

		scanf("%d %d", &W, &H);

		if (W == 0) break;

		int cx, cy;

		for (int y = 0; y < H; y++) {
			char buf[21];
			scanf("%s", buf);
			for (int x = 0; x < W; x++) {
				board[x][y] = buf[x];
				if (buf[x] == '@') {
					cx = x; cy = y;
				}
			}
		}

		printf("%d\n", count(cx, cy));
	}

	return 0;
}

C++: #include<iostream>
#include<stdlib.h>

using namespace std;

char map[100][100];
char smap[100][100];
int ans;

int serch(int nx,int ny,int maxx,int maxy)
{
	int nextx[4]={1,0,-1,0},nexty[4]={0,1,0,-1};
	map[ny][nx]='0';
/*///////////////ツ確ツ認ツ用////////////////////	
	getchar();
	
	system("cls");
	
	cout << "nowx:" << nx << " mowy:" << ny << "maxx:" << maxx << " maxy:" << maxy << endl;
	cout << maxx << " " << maxy << endl;
	for(int i=0;i<maxy;i++)
	{
		for(int j=0;j<maxx;j++)
		{
			cout << smap[i][j];
		}
		cout << endl;
	}
	cout << endl;
	for(int i=0;i<maxy;i++)
	{
		for(int j=0;j<maxx;j++)
		{
			cout << map[i][j];
		}
		cout << endl;
	}
*//////////////////////////////////////////	
	for(int i=0;i<4;i++)
	{
		if(0<=nx+nextx[i] && nx+nextx[i]<maxx && 0<=ny+nexty[i] && ny+nexty[i]<maxy &&map[ny+nexty[i]][nx+nextx[i]]=='.')
		{
//				cout << "nextx:" << nx+nextx[i] << " nexty:" << ny+nexty[i] << endl;
				serch(nx+nextx[i],ny+nexty[i],maxx,maxy);
		}
	}
	return ans++;
}

int main()
{
	int x,y;
	int i,j;
	int sx,sy;
	
	for(;;)
	{
		cin >> x >> y ;
		
		if(x==0 && y==0)
			break;
		
		for(i=0;i<y;i++)
		{
			for(j=0;j<x;j++)
			{
				cin >> map[i][j];
				smap[i][j]=map[i][j];
				if(map[i][j]=='@')
				{
					sx=j;
					sy=i;
				}
			}
		}
		
		ans=0;
		serch(sx,sy,x,y);
		
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<ll,ll> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int w,h,bx,by,sum=0;
char m[21][21];

void dfs(int x,int y)
{
    if(m[y][x]=='#')return;
    if(m[y][x]=='.'){sum++;m[y][x]='#';}
    REP(i,4)
    {
        int xx=x+dx[i];
        int yy=y+dy[i];
        if(xx>=0&&xx<w&&yy>=0&&yy<h)dfs(xx,yy);
    }
}

int main()
{   
    while(cin>>w>>h,w){
    sum=0;
    REP(i,h)REP(j,w)
    {
        cin>>m[i][j];
        if(m[i][j]=='@'){bx=j;by=i;m[i][j]='.';}
    }
    dfs(bx,by);
    cout<<sum<<endl;
    }
}

C++: #include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
inline bool scan(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
void scan(string &s) {for (char c; !isspace(c = gcu()); s += c);}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

typedef vector<string> maze;
int walk(int x, int y, maze &m) {
	static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	if (x < 0 || x >= (int) m[0].size() ||
		y < 0 || y >= (int) m.size() ||
		m[y][x] == '#' || m[y][x] == 'X')
		return 0;
	m[y][x] = 'X';
	int c = 1;
	for (int i = 0; i < 4; i++)
		c += walk(x + dx[i], y + dy[i], m);
	return c;
}

int main() {
	int W, H;
	while(scan(W) && scan(H) && (W || H)) {
		maze m(H);
		int i = 0, x = 0, y = 0;
		for (auto &s: m) {
			for (int c; !isspace(c = gcu()); s += c)
				if (c == '@')
					y = i, x = s.size();
			i++;
		}
		out(walk(x, y, m), '\n');
	}
}