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 <vector>
#include <algorithm>
#include <string>

using namespace std;

int solve( int w, int h, vector< vector<char> > &v );
void dfs( int W, int H, int w_index, int h_index, vector< vector<char> > &V, int &ans );

int main(int argc, char const *argv[]) {
    vector< vector<char> > vec;

    int w, h;
    vector<int> sums;

    while (1) {
        cin >> w >> h;

        if( w==0 || h==0 ) break;

        vec.resize(h);
        for (int i = 0; i < h; i++) {
            vec[i].resize(w);
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> vec[i][j];
            }
        }

        sums.push_back( solve( w, h, vec ) );
    }

    for( auto it = sums.begin(); it != sums.end(); it ++ ){
        cout << *it << endl;
    }

    return 0;
}

int solve( int w, int h, vector< vector<char> > &v ){
    int w_index, h_index, total;
    int ans = 1;

    for (auto it = v.begin(); it != v.end(); it++ ) {
        auto iter = find(it->begin(), it->end(), '@');

        if(iter!=it->end()){
            h_index = distance( v.begin(), it );
            w_index = distance( it->begin(), iter );
        }
    }
    std::cout << "index:"<< w_index << "," << h_index << std::endl;
    dfs( w, h, w_index, h_index, v, ans );

    return ans;
}

void dfs( int W, int H, int w_index, int h_index, vector< vector<char> > &V , int &ans ){
    int dx[4] = { 1, 0, -1, 0 };
    int dy[4] = { 0, 1, 0, -1 };
    V[h_index][w_index] = '#';

    for( int i = 0; i < 4; i++ ){
        int nx = w_index + dx[i];
        int ny = h_index + dy[i];

        if( 0 <= nx && nx < W && 0 <= ny && ny < H && V[ny][nx] == '.' ){
            std::cout << nx << ","<< ny << std::endl;
            ans++;
            dfs( W, H, nx, ny, V, ans );
        }
    }

    return;
}

C++: #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int W,H,f[20][20],ans[50],cnt=0,sx,sy;
string m[20];

void find(int x,int y){
	if(x>=W || x<0 || y>=H || y<0)return;
	string t;
	t = m[x][y];
	if(t=="#")return;
	if(f[x][y]!=0)return;
	f[x][y] = 1;
	ans[cnt]++;
	find(x+1,y);
	find(x-1,y);
	find(x,y+1);
	find(x,y-1);
}

int main(void){
	while(1){
		cin>>W>>H;
		if(W==0 && H==0)break;
		ans[cnt]=0;
		rep(i,H){
			string s;
			cin>>s;
			rep(j,W){
				f[j][i]=0;
				m[j][i]=s[j];
				string t;
				t=m[j][i];
				if(t=="@"){
					sx=j;
					sy=i;
				}
			}
		}
		find(sx,sy);
		cnt++;
	}
	rep(i,cnt)cout<<ans[i]<<endl;
	return 0;
}

C++: #include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

int w,h;
char B[20][21];

int dfs(int i,int j){
	B[i][j]='#';
	int res=1;
	rep(k,4){
		int y=i+dy[k],x=j+dx[k];
		if(0<=y && y<h && 0<=x && x<w && B[y][x]=='.') res+=dfs(y,x);
	}
	return res;
}

int main(){
	for(;scanf("%d%d",&w,&h),w;){
		rep(i,h) scanf("%s",B[i]);
		rep(i,h) rep(j,w) if(B[i][j]=='@') printf("%d\n",dfs(i,j));
	}
	return 0;
}

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

int ans;
bool check[20][20];
char maze[20][20];

void init()
{
	for (int i = 0; i < 20; ++i) {
		for (int j = 0; j < 20; ++j) {
			check[i][j] = false;
			maze[i][j] = '\0';
		}
	}
}

void search(int y, int x, int h, int w)
{
	if (y >= h || x >= w || y < 0 || x < 0 || check[y][x] || maze[y][x] == '#') {
		return;
	}

	check[y][x] = true;
	++ans;
	search(y + 1, x, h, w);
	search(y - 1, x, h, w);
	search(y, x + 1, h, w);
	search(y, x - 1, h, w);
}

int main(void)
{
	int w, h;
	while (cin >> w >> h && w != 0) {
		ans = 0;
		init();
		int sx, sy;
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				cin >> maze[y][x];
				if (maze[y][x] == '@') {
					sx = x;
					sy = y;
				}
			}
		}
		search(sy, sx, h, w);
		cout << ans << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	while(1){
		int i,j,k,w,h,a;
		char c[20][20];
		cin>>w>>h;
		if(w==0&&h==0)break;
		for(i=0;i<20;i++){
			for(j=0;j<20;j++){
				c[i][j]='\0';
			}
		}
		
		
		for(i=0;i<h;i++){
			cin>>c[i];
		}
		for(k=0;k<=w*h;k++){
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(c[i][j]=='.'){
						if(i!=h-1){
							if(c[i+1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=w-1){
							if(c[i][j+1]=='@'){
								c[i][j]='@';
							}
						}
						if(i!=0){
							if(c[i-1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=0){
							if(c[i][j-1]=='@'){
								c[i][j]='@';
							}
						}
					}	
				}
			}
		}
		

		a=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(c[i][j]=='@')a++;	
			}
		}
		cout<<a<<endl;
	}

    return 0;
}

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

int W,H;
int count=0;

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


vector<vector<char> > M;

void go(int x,int y){
	if(x<0 || y<0 || x>=W || y>=H) return;
	if(M[y][x]=='.' || M[y][x]=='@'){
		count++;
		M[y][x]='#';
		for(int r=0;r<4;r++){
			go(x+dx[r],y+dy[r]);
		}
	}
}

void solve(){
	count=0;

	M.clear();
	M.resize(H,vector<char>(W));

	int sx,sy;
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			char t;
			cin>>t;
			M[y][x]=t;
			if(t=='@'){
				sx=x;sy=y;
			}
		}
	}

	go(sx,sy);
	cout<<count<<endl;

}


int main(){
	while(cin>>W>>H){
		if(W==0) return 0;
		solve();
	}
}