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>

using namespace std;

int W,H;
int posW, posH;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
bool tiles[21][21] = {};
bool v_tiles[21][21] = {};

void dfs(int x, int y) {
    if (!(0 <= x && x <= W-1 && 0 <= y && y <= H-1) || v_tiles[x][y] == true || tiles[x][y] == true)
        return;

    v_tiles[x][y] = true;
    for (int i = 0; i < 4; i++) {
        dfs(x+dx[i], y+dy[i]);
    }
}

int main() {
    while (cin>>W>>H && W != 0 && H != 0) {
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                v_tiles[w][h] = false;
                char tile;
                cin>>tile;
                switch (tile) {
                    case '.':
                        tiles[w][h] = false;
                        break;

                    case '#':
                        tiles[w][h] = true;
                        break;

                    case '@':
                        tiles[w][h] = false;
                        posW = w;
                        posH = h;
                        break;
                }
            }
        }

        dfs(posW, posH);

        int count = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                if (v_tiles[w][h] == true) count++;
            }
        }
        cout<<count<<endl;;
    }
}

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( x < H && y < W && room[y][x] == '.' ){
					room[y][x] = '*';
					xy.push(pair<int, int>(y, x));
					sum++;
				}
			}
			//cout << endl;
			xy.pop();
		}
		/*for( int i = 0; i < H; i++ ){
			for( int j = 0; j < W; j++ ){
				cout << room[i][j];
			}
			cout << endl;
		}*/
		cout << sum << endl;
	}
}

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAX = 20;
char map[MAX][MAX];
bool book[MAX][MAX];
struct Point
{
	int x;
	int y;
	Point(int x = 0, int y = 0) :x(x), y(y) {}
}start;
int sum = 0;
void depthFSearch(int H, int W, Point start)
{
	int next[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };
	for (int k = 0; k <= 3; k++)
	{
		int nx = start.x + next[k][0];
		int ny = start.y + next[k][1];
		if (nx < 0 || nx >= H || ny < 0 || ny >= W||map[nx][ny]=='#')
			continue;
		if (!book[nx][ny] && map[nx][ny] == '.')
		{
			book[nx][ny] = true;
			Point p(nx, ny);
			sum++;
			depthFSearch(H, W, p);
		}
	}
	return;
}
int main()
{
	while (true)
	{
		int H, W;
		cin >> H >> W;
		if (!H && !W)
			break;
		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
			{
				cin >> map[i][j];
				if (map[i][j] == '@')
					start = Point(i, j);
			}
		book[start.x][start.y] = true;
		sum = 1;
		depthFSearch(H, W, start);
		cout << sum << endl;
	}
}

C++: #include <iostream>
using namespace std;
int w,h;
char ma[100][100];
int sx,sy; 
int dx[] = {0,0,1,-1},dy[] = {1,-1,0,0};
int cnt;
int dfs(int px,int py){
  ma[py][px] = '#';
  cnt++;
  for(int i = 0 ; i < 4 ; i++){
    int nx = px + dx[i],ny = py + dy[i];
    if(0 <= nx && nx < w && 0 <= ny && ny < h &&
       ma[ny][nx] != '#'){
      if(ma[ny][nx] == '.')dfs(nx,ny);
    }
  }
  return cnt;
}

int main(){
  while( cin >> w >> h, w + h){
    cnt = 0;
    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;
  }
}

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

int moved = 0;
int w, h;
char myMap[20][20];

bool safe(int x, int y){
    return (x < h && y < w) && (x >= 0 && y >= 0);
}

void move(int x, int y){
    myMap[x][y] = '#';
    moved++;
    if (myMap[x+1][y] == '.' && safe(x+1, y)) move(x+1, y);
    if (myMap[x-1][y] == '.' && safe(x-1, y)) move(x-1, y);
    if (myMap[x][y+1] == '.' && safe(x, y+1)) move(x, y+1);
    if (myMap[x][y-1] == '.' && safe(x, y-1)) move(x, y-1);
    return;
}

int main(){
    while (1){
	cin >> w >> h;
	if (w == 0 && h == 0) break;

	moved = 0;
	int initX, initY;

	for (int i = 0; i < h; i++){
	    for (int j = 0; j < w; j++){
		cin >> myMap[i][j];
		if (myMap[i][j] == '@'){
		    initX = i;
		    initY = j;
		}
	    }
	}
	
	move(initX, initY);
	
	cout << moved << endl;
    }
}