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>
#define BLACK 1
#define RED 2
#define ARUKERUYO 10
using namespace std;

void aaa(int *data, int n, int a, int b){

  data[n] = ARUKERUYO;

  if(data[n-a] == BLACK && n-a >= 0) aaa(data,n-a,a,b);
  if(data[n-1] == BLACK && n%a != 0) aaa(data,n-1,a,b);
  if(data[n+1] == BLACK && n%a != a-1) aaa(data,n+1,a,b);
  if(data[n+a] == BLACK && n+a <= a*b-1) aaa(data,n+a,a,b);

  return;
}

int main(){
  int a,b;

  while(cin>>a>>b){
    if(a==0&&b==0)
      break;
    char sym;
    int data[a*b];
    int stand;

    for(int i=0;i<a*b;i++){
      cin >> sym;
      if(sym=='.')
	data[i] = BLACK;
      else if(sym=='#')
	data[i] = RED;
      else
	stand = i;
    }
    aaa(data,stand,a,b);
    stand = 0;
    for(int i=0;i<a*b;i++)
      if(data[i] == ARUKERUYO)
	stand++;
    cout << stand << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
using namespace std;
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };

int main(){
	int W, H;
	while( cin >> W >> H, W, H ){
		char room[20][20];
		queue< pair<int, int> > xy;
		for( int i = 0; i < H; i++ ){
			for( int j = 0; j < W; j++ ){
				cin >> room[i][j];
				if( room[i][j] == '@' ){
					xy.push(pair<int, int>(i, j));
					room[i][j] = '#';
				}
			}
		}
		//cout << xy.front().first << ' ' << xy.front().second << endl;
		int sum = 1;
		while( !xy.empty() ){
			for( int i = 0; i < 4; i++ ){
				int x = xy.front().second + dx[i];
				int y = xy.front().first + dy[i];
				//cout << room[y][x];
				if( room[y][x] == '.' ){
					room[y][x] = '#';
					xy.push(pair<int, int>(y, x));
					sum++;
				}
			}
			//cout << endl;
			xy.pop();
		}
		cout << sum << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

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

int w, h;
struct xydata {
    int x, y;
};

int main() {
    while(1) {
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        int sx, sy;
        vector< vector<char> > tile(h, vector<char>(w, '.'));
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                cin >> tile[i][j];
                if(tile[i][j] == '@') {
                    sx = j; sy = i;
                }
            }
        }
        vector< vector<char> > ntile = tile;
        queue<xydata> que;
        xydata first; first.x = sx; first.y = sy;
        que.push(first);
        ntile[sy][sx] = '#';
        while(!que.empty()) {
            xydata now = que.front();
            que.pop();
            for(int i = 0; i < 4; ++i) {
                int nx = now.x+dx[i], ny = now.y+dy[i];
                if(nx >= 0 && nx < w && ny >= 0 && ny < h) {
                    if(ntile[ny][nx] == '.') {
                        xydata next;
                        next.x = nx, next.y = ny;
                        que.push(next);
                        ntile[ny][nx] = '#';
                    }
                }
            }
        }

        int cnt = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                if(tile[i][j] == '.' || tile[i][j] == '@') {
                    if(ntile[i][j] == '#') cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <functional>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1 };


int main()
{
	while (true)
	{
		int W, H;
		cin >> W >> H;
		if (W == 0 && H == 0) break;

		char C[30][30];
		int B[30][30];
		for (int i = 0; i < H; i++)
		{
			scanf("%s", C[i]);
		}
		int sx = -1; int sy = -1;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				B[i][j] = 0;
				if (C[i][j] == '@')
				{
					sy = i;
					sx = j;
				}
			}
		}

		queue<pi> Q;
		Q.push(pi(sy, sx));
		B[sy][sx] = 1;
		int ans = 1;
		while (!Q.empty())
		{
			int ty = Q.front().first; int tx = Q.front().second;
			Q.pop();

			for (int r = 0; r < 4; r++)
			{
				int y = ty + dd[r];
				int x = tx + dd[r + 1];
				if (y < 0 || y >= H || x < 0 || x >= W)continue;
				if (C[y][x] == '#')continue;
				if (B[y][x])continue;
				ans++;
				B[y][x] = 1;
				Q.push(pi(y, x));
			}
		}

		cout << ans << endl;
	}
	return 0;
}

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

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

char ma[30][30];

int W,H;
int dfs(int nx,int ny){
	if(ma[ny][nx]=='#')return 0;
	ma[ny][nx]='#';
	int re=1;
	for(int i=0;i<4;i++){
		int nex=nx+dx[i],ney=ny+dy[i];
		if(nex>=0 && ney>=0 && nex<W && ney<H)re+=dfs(nex,ney);
	}
	return re;
}


int main(){
	int sx,sy;
	while(cin>>W>>H && W+H){
		for(int i=0;i<H;i++)for(int j=0;j<W;j++){
			cin>>ma[i][j];
			if(ma[i][j]=='@'){sx=j,sy=i;}
		}
		cout<<dfs(sx,sy)<<endl;
	}
	
}