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>
#include <algorithm>
using namespace std;

int W,H,map[20][20];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

void dfs(int x,int y) {
	map[x][y]=0;
	for(int i=0;i<4;i++) {
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx&&nx<W&&0<=ny&&ny<H&&map[nx][ny]=='.') dfs(nx,ny);
	}
}

int main() {
	int x,y;
	while(scanf("%d %d",&W,&H),W||H) {
		getchar();
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				map[i][j]=getchar();
				if(map[i][j]=='@') {
					map[i][j]='.';
					x=i,y=j;
				}
			}
			getchar();
		}
		dfs(x,y);
		int ans=0;
		for(int j=0;j<H;j++) {
			for(int i=0;i<W;i++) {
				ans+=!map[i][j];
			}
		}
		printf("%d\n",ans);
	}
}

C++: #if 0
08-162015?????????????????°???????????????????????????
pair???
#endif

#include <iostream>
#include <queue>
using namespace std;

int w,h;
int tot=1; //?????£????????????(?????????????????????)
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1}; //??????????§??????¨
char P[30][30]; //??§?¨?????????????????????¨???

bool valid(int x,int y){ //??????????????????
	return (x>=0)&&(x<w)&&(y>=0)&&(y<h)&&(P[x][y]!='#');
}

void bfs(int x,int y){ //???????????¢?´¢
	queue<pair<int,int> > q;
	pair<int,int> p;
	p = make_pair(x,y); //pair??????????????¨??????????????????
	q.push(p);
	while(!q.empty()){
		pair<int,int> cur=q.front(); //?????¨??°?????????????????????
		q.pop();
		for(int i=0;i<4;++i){
			if(valid(cur.first+dx[i],cur.second+dy[i])){
				q.push(make_pair(cur.first+dx[i],cur.second+dy[i]));
				tot++;
				P[cur.first+dx[i]][cur.second+dy[i]]='#'; //???????????£?????´???????°???????
			}
		}
	}
}

int main(){
	int x1,y1;
	while((cin>>w>>h)&&(w!=0)){
		for(int j=0;j<h;++j){
			for(int i=0;i<w;++i){
				cin>>P[i][j];
				if(P[i][j]=='@')
					x1=i; y1=j; 
			}
		}
		bfs(x1,y1); //??????????????°????????£??\????????¢?´¢????§?
	}
	cout << tot <<endl;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it = (c).begin(); it != (c).end(); it++)
#define X first
#define Y second

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 20;

int w, h, cnt;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
vs m(N);

void dfs(pii);

int main(void){
    for(; cin >> w >> h, w; cout << cnt << endl){
        cnt = 0;
        pii p;

        rep(y, h){
            cin >> m[y];
            rep(x, w) if(m[y][x] == '@') m[y][x] = '.', p = mp(x, y);
        }
        
        dfs(p);
    }

    return 0;
}

void dfs(pii p){
    if(p.X < 0 || w <= p.X ||
       p.Y < 0 || h <= p.Y || m[p.Y][p.X] == '#') return;

    cnt++;
    m[p.Y][p.X] = '#';
    
    rep(i, 4) dfs(mp(p.X + dx[i], p.Y + dy[i]));
}

C++: #include<iostream>
#include<cstdio>
#include<string.h>
#define rep(i,n) for(int i =0;i<n;i++)
using namespace std;

string t[21];
int w,h;

void dfs(int x,int y){
int dx[4] = {1,-1, 0, 0};
int dy[4] = {0, 0, 1, -1};


	if(((x<0||y<0)||x>=h||y>=w)||t[x][y]!='.') return;
	t[x][y]='@';	
	rep(k,4){
	dfs(x+dx[k],y+dy[k]);
}
return;
}


int main(void){
	int sx=-1,sy=-1,cnt;
	
while(true){
scanf("%d %d/n",&w,&h);
if(!w&&!h) {break;}
rep(i,h){
cin >> t[i];
}

rep(i,h)rep(j,w){

	if(t[i][j]=='@'){	
	sx =i;
	sy =j;

t[i][j]='.';
	}

}

dfs(sx,sy);

cnt =0;

rep(i,h)rep(j,w)if(t[i][j]=='@') cnt++;	

cout<<cnt<<endl;;


}

return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>

using namespace std;

char room[25][25] = {'#'};

int walk(int x, int y) {
    int ret = 1;
    room[y][x] = '#';
    if (room[y-1][x] == '.') ret += walk(x, y-1);
    if (room[y+1][x] == '.') ret += walk(x, y+1);
    if (room[y][x-1] == '.') ret += walk(x-1, y);
    if (room[y][x+1] == '.') ret += walk(x+1, y);
    return ret;
}

int main() {
    int W, H;
    while (cin >> W >> H, W || H) {
        int x, y;
        for (int i=0; i<25; ++i) {
            for (int j=0; j<25; ++j) {
                room[i][j] = '#';
            }
        }
        for (int i=1; i<=H; ++i) {
            for (int j=1; j<=W; ++j) {
                cin >> room[i][j];
                if (room[i][j] == '@') {
                    room[i][j] = '.';
                    y = i, x = j;
                }
            }
        }
        cout << walk(x, y) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <cctype>
#include <algorithm>
#include <string>
#include <queue>
#include <cstring>
using namespace std;

char map[21][21];
int w, h;
int tile = 0;

void dfs(int x, int y){
    if (!(0 <= x && x < w && 0 <= y < h)) return;
    tile++;
    map[y][x] = '#';
    if (map[y-1][x] == '.') dfs(x, y-1);
    if (map[y+1][x] == '.') dfs(x, y+1);
    if (map[y][x-1] == '.') dfs(x-1, y);
    if (map[y][x+1] == '.') dfs(x+1, y);
}

int main(){
    int sx, sy;
    while (cin >> w >> h, w || h){
	memset(map, '#', sizeof(map));
	tile = 0;
	for (int i = 0; i < h; i++){
	    cin >> map[i];
	    for (int p = 0; p < w; p++){
		if (map[i][p] == '@'){
		    sx = p;
		    sy = i;
		}
	    }
	}

	dfs(sx, sy);

	cout << tile << endl;
    }
    
    return 0;
}

C++: #include<stdio.h>

char map[32][32];
int ans;
int W,H;

void func(int x,int y){
	map[x][y] = '0';
	ans++;
	if(map[x][y+1] == '.' && y+1<32)
		func(x,y+1);
	if(map[x][y-1] == '.' && y-1>-1)
		func(x,y-1);
	if(map[x+1][y] == '.' && x+1<32)
		func(x+1,y);
	if(map[x-1][y] == '.' && x-1>-1)
		func(x-1,y);
}


int main(void){
	while(scanf("%d%d",&W, &H) && H){
		for(int i = 0; i < H; i++){
			scanf("%s",map[i]);
		}
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(map[i][j] == '@'){
					func(i,j);
				}
			}
		}
		printf("%d\n",ans);
		ans=0;
		for(int i = 0; i < 32; i++){
			for(int j = 0; j < 32; j++){
				map[i][j] = 0;
			}
		}
	}
	return 0;
}