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;
#define MAX 21

string str[MAX];
int n,m,cnt,dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

void dfs(int x,int y){
  str[x][y] = '#';

  for(int i = 0 ; i < 4 ; i++){
    int nx = x + dx[i] , ny = y + dy[i];
    if(0 <= nx && nx < m && 0 <= ny && ny < n){
      if(str[nx][ny] == '.'){
	cnt++;
	dfs(nx,ny);
      }
    }
  }

  return;
}

int main(){
  while(cin >> n >> m , n + m){
    for(int i = 0 ; i < m ; i++)
      cin >> str[i];
    
    int x,y;
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < m ; j++){
	if(str[j][i] == '@'){
	  x = j;
	  y = i;
	  break;
	}
      }
    }
    cnt = 1;
    dfs(x,y);
    cout << cnt << endl;

  }

  return 0;
}

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

struct P {
  int x, y;
  P(int x, int y) : x(x), y(y) { }
};

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

int main() {
  for(int W, H; cin >> W >> H && W; ) {
    vector<string> M;
    queue<P> que;

    for(int y = 0; y < H; y++) {
      string line;
      cin >> line;

      M.push_back(line);

      for(int x = 0; x < W; x++) {
        if(M[y][x] == '@') {
          que.push(P(x, y));
        }
      }
    }

    int answer = 0;
    for(; !que.empty(); que.pop()) {
      P p = que.front();
      answer++;

      for(int i = 0; i < 4; i++) {
        int nx = p.x + dx[i], ny = p.y + dy[i];

        if(0 <= nx && nx < W && 0 <= ny && ny < H && M[ny][nx] == '.') {
          M[ny][nx] = '#';
          que.push(P(nx, ny));
        }
      }
    }

    cout << answer << endl;
  }
}

C++: #include <iostream>

using namespace std;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
int w, h;
char map[21][21];
int cnt;

void dfs(int x, int y)
{
    cnt++;
    map[y][x] = '#';

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

        if (nx < 0 || ny < 0 || nx >= w || ny >= h) 
            continue;
        else if (map[ny][nx] == '.') {
            dfs(nx, ny);
        }
    }
}

int main()
{
    while (cin >> w >> h, w || h) {
        int sx, sy;

        for (int y = 0; y < h; y++)
            for (int x = 0; x < w; x++) {
                cin >> map[y][x];
                if (map[y][x] == '@') {
                    sx = x;
                    sy = y;
                }
            }

        cnt = 0;
        dfs(sx, sy);
        cout << cnt << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <queue>

using namespace std;

int main(){
    int w,h;
    while(cin >> w >> h && w!=0){
        int t[w+2][h+2];
        for(int i=0;i<w+2;i++){
            for(int j=0;j<h+2;j++){
                t[i][j] = 0;
            }
        }

        int ** matrix = new int*[w*h];
        for( int i=0; i<w*h; i++ ) {
            matrix[i] = new int[w*h];
        }

        int start;
        for(int i=0;i<h+2;i++){
            for(int j=0;j<w+2;j++){
                if(i==0 || j==0 || i==w+1 || j==h+1)
                    t[i][j]=0;
                else{
                    char tmp; cin >> tmp;
                    if(tmp=='.'){
                        t[i][j] = 1;
                    }
                    else if(tmp=='#'){
                        t[i][j] = 0;
                    }
                    else{
                        t[i][j] = 1;
                        start = i*w+j;
                    }
                }
            }
        }
        for(int i=0;i<w*h;i++){
            for(int j=0;j<w*h;j++){
                matrix[i][j] = 0;
            }
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0 || j==0 || i==w || j==h)
                    continue;
                else{
                    int id = i*w+h;
                    if(t[(id-w)/w+1][(id-w)%w+1] == 1)
                        matrix[id][id-w] = 1;
                    if(t[(id+w)/w+1][(id+w)/w+1] == 1)
                        matrix[id][id+w] = 1;
                    if(t[(id-1)/w+1][(id-1)/w+1] == 1)
                        matrix[id][id-1] = 1;
                    if(t[(id+1)/w+1][(id+1)/w+1] == 1)
                        matrix[id][id+1] = 1;
                }
            }
        }
        int count = 1;
        queue<int> Q;
        int came[w*h];
        for(int i=0;i<w*h;i++){
            came[i] = 0;
        }
        Q.push(start);
        came[start] = 1;
        while(Q.size()!=0){
            int cur = Q.front();
            for(int i=0;i<w*h;i++){
                if(matrix[cur][i]==1 && came[i] == 0){
                    Q.push(i);
                    came[i] = 1;
                    count++;
                }
            }
            Q.pop();
        }
        cout << count << endl;
        for( int i=0; i<w*h; i++ ) {
            delete[] matrix[i];
        }
        delete[] matrix;

    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int w;
int h;
int ans;
vector <vector<char>> maps;

bool check(int x, int y){
if (0>x || x>=h || 0>y || y>=w){
return false;
}
if (maps[x][y]!='.'){
return false;
}
return true;
}

void bfs(int x, int y){
vector <vector<int>> move = {{1,0},{-1,0},{0,1},{0,-1}};
for (const auto& e: move){
if (check(x+e[0],y+e[1])){
ans+=1;
maps[x+e[0]][y+e[1]]='#';
bfs(x+e[0],y+e[1]);
}
}
}

int main(){
cin >> w >> h;
bool flag = false;
int pos_x;
int pos_y;
while (w!=0 || h!=0){
vector <vector<char>> rawmaps(h,vector<char>(w+1));
ans = 0;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
cin >> rawmaps[i][j];
if (rawmaps[i][j]=='@'){
pos_x=i;
pos_y=j;
}
}
}
maps = rawmaps;

bfs(pos_x,pos_y);
cout << ans+1 << endl;
cin >> w >> h;
}
}