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 <string>
#include <vector>
using namespace std;
int W, H, sx, sy, cnt;
vector<int> dxy = { 1, 0, -1, 0, 1 }; 
string field[20];

void fun(int y, int x){
    field[y][x] = '#';
    cnt++;
    for(int i=0; i<4; ++i){
        int ny = y + dxy[i+1],
            nx = x + dxy[i];
        if(ny < 0 || ny >= H ||nx < 0 || nx >= W || field[ny][nx] != '.') continue;
        fun(ny, nx);
    }
}
    
int main(){
    while(cin >> W >> H, (W||H)){
        cnt = 0;
        string str;
        cin.ignore();
        for(int i=0; i<H; ++i){
            cin >> field[i];
        }
        for(int i=0; i<H; ++i){
            for(int j=0; j<W; ++j){
                if(field[i][j] == '@'){
                    sx = j; sy = i;
                }
            }
        }
        fun(sy, sx);
        cout << cnt << 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( x < W && y < H && 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<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
//Global
int x, y;
const int MAX_N = 20;
char maze[MAX_N][MAX_N+1];
const int INF = 1000000;
int X, Y;//"@"???????????????
int memo[MAX_N][MAX_N];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
int counter;

void bsd(int a, int b) {
	maze[b][a] = '#';
	memo[b][a] = INF;
	counter++;
	for (int i = 0; i < 4; i++) {
		int nx = a + dx[i];
		int ny = b + dy[i];
		if (memo[ny][nx] == 0 && maze[ny][nx] == '.' && 0 <= nx && nx < x && 0 <= ny && ny < y) {
			bsd(nx, ny);
		}
	}

}



//solve
//??±???????????¢?´¢??§"@"??¨???????????£?????????"."????????°????±???????
void solve()
{
	//memo????????????
	memset(memo,0, sizeof(memo));
	//for (int i = 0; i < y; i++) {
		//for (int j = 0; j < x; j++) {
			//memo[i][j] = 0;
	//	}
	//}

	//"@"??¨??£??\????????????  ??????  INF??§??????  ??????  ????????????????????£?????????????????????"."??§??????
	counter = 0;//"@"??????
	bsd(X, Y);


	cout << counter << endl;

}


//main
int main()
{
	while (true) {
		cin >> x >> y;
		if (x == 0 && y == 0)break;
		//"W"??¨"."??¨"@"?????\???
		for (int i = 0; i < y; i++) {
			for (int j = 0; j < x; j++) {
				cin >> maze[i][j];
				if (maze[i][j] == '@') {
					X = j; Y = i;//@???????????????????¨????
				}
			}
		}
		solve();
	}
    return 0;
}

C++: #include <iostream>
#include <string>
#define GROUND 0
#define WALL 500
#define INITIAL -1

int count();
void init();
void mark_n(int,int,int,int,int);
void mark_n_all(int);
bool isValidPoint(int,int);

using namespace std;
const int MAX_W = 20;
const int MAX_H = 20;
char floor_[MAX_W][MAX_H];
//floorツつセツづ算ツ術ツ甘鳴青板づ債ャツつエツづゥ
int step[MAX_W][MAX_H];
int width,height;

int main(){
  while(cin >> width >> height && width > 0){
    string line;
    int ix,iy;
    init();
    for(int i = 0; i < height; i++){
      cin >> line;
      for(int j=0; j < width ; j++){
	floor_[j][i] = line[j];
	if(line[j]=='@'){
	  step[j][i]=GROUND;
	  ix = j; iy = i;
	}else if(line[j]=='#'){
	  step[j][i]=WALL;
	}
      }
    }
    for(int k = 0; k < 300; k++){
      mark_n_all(k);
    }
    cout << count() << endl;
  }
}

int count(){
  int result =0;
  for(int i=0; i<height;i++){
    for(int j=0; j< width; j++){
      if(step[j][i] >= 0 && step[j][i] < WALL){
	result++;
      }
    }
  }
  return result;
}

void init(){
  for(int i=0; i<height;i++){
    for(int j=0; j< width;j++){
      step[j][i]=INITIAL;
    }   
  }
}

void mark_n(int n,int x,int y,int dx,int dy){
  int temp;
  for(int i =0; i< 4;i++){
    temp = dx;
    dx = dy;
    dy = -temp;
    if(isValidPoint(x+dx,y+dy) && step[x+dx][y+dy]==INITIAL){
      step[x+dx][y+dy] = n;
    }
  }
}

void mark_n_all(int n){
  for(int i = 0; i < height; i++){
    for(int j = 0; j < width ; j++){
      if(step[j][i]==n){
	mark_n(n+1,j,i,1,0);
      }
    }
  }
}

bool isValidPoint(int x,int y){
  if(x < 0 || x >=  width || y < 0 || y >= height){
    return false;
  }else{
    return true;
  }
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};

int ans = 0;
int W,H;

bool in_range(int x,int y) {
	if (0 <= x and x < W and 0 <= y and y < H) {
		return true;
	}else {
		return false;
	}
}
int dfs(vector<string> &tab,int x, int y) {
	int ret = 0;
	if (tab[y][x] == '#' or tab[y][x] == '/') return  0;
	if (tab[y][x] == '.') {
		ret += 1;
		tab[y][x] = '/';
	}

	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (in_range(nx,ny)) {
			ret += dfs(tab,nx,ny);	
		}
	}
	return ret;
}

void printv(vector<string> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << endl;
	}
}

int main() {
	
	while(1) {
		cin >> W >> H;
		if (W + H == 0) break;
		int x,y;
		vector<string> tab;
		for (int i = 0; i < H; i++) {
			string s; cin >> s;
			tab.push_back(s);
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (tab[i][j] == '@') {
					x = j;
					y = i;
				}
			}
		}
		//printv(tab);
		cout << dfs(tab,x,y) + 1 << endl;
		//printv(tab);
	}

	return 0;
}