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 <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;

void merge (int *first1, int *last1, int *first2, int *last2){
    int size1 = last1 - first1;
    int size2 = last2 - first2;
    int *result = new int[size1+size2];
    int i = 0;
    int j = 0;
    int index = 0;
    while (true){
        if (i < size1 && (first1[i] <= first2[j] || j >= size2)){
            result[index] = first1[i];
            ++i; ++index;
        }
        if (j < size2 && (first1[i] > first2[j] || i >= size1)){
            result[index] = first2[j];
            ++j; ++index;
        }
        if (i==size1 && j==size2){
            for (i=0; i<size1; ++i) first1[i] = result[i];
            for (j=0; j<size2; ++j) first2[j] = result[j+size1];
            delete[] result;
            return;
        }
    }
}
void MergeSort (int *first, int *last){
    int size = last - first;
    if(size <= 1) return;
    MergeSort(first, first+size/2);
    MergeSort(first+size/2, last);
    merge(first, first+size/2, first+size/2, last);
}


int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int dx[3]={-1, 0, 1};
int dy[3]={-1, 0, 1};
int W, H;
char masu[20][20];
int cnt;

int dfs(int a, int b){
  masu[a][b] = '#';
  cnt++;
  REP(i, 3)REP(j, 3) if(masu[a+dx[i]][b+dy[j]]=='.' && abs(dx[i]+dy[j])==1 && a+dx[i] >= 0 && a+dx[i] < W && b+dx[j] >= 0 && b+dx[j] < H) dfs(a+dx[i], b+dy[j]);
  return cnt;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    REP(j, H)REP(i, W) cin >> masu[i][j];

    int i0, j0;
    REP(j, H)REP(i, W) if(masu[i][j] == '@'){
      i0=i;
      j0=j;
      break;
    }

    cnt = 0;
    cnt = dfs(i0, j0);
    cout << cnt << endl;
  }
    return 0;
}

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

using namespace std;
vector <vector<int> > randb (vector <vector<char> >tile,vector <vector<int> > canmove,int si,int sj,int w,int h);
int main(){
  int w,h;
  cin >> w >> h;
  while(w != 0 || h != 0){
    vector <vector<char> > tile(h,vector<char>(w));
    vector <vector<int> > canmove(h,vector<int>(w,0));
    int si,sj;
    int cnt = 0;
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
        cin >> tile[i][j];
        if(tile[i][j] == '@'){
          canmove[i][j] = 1;
          si = i;
          sj = j;
        }
      }
    }
    canmove = randb(tile,canmove,si,sj,w,h);
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
          cnt += canmove[i][j];
        }
      }
      cout << cnt << endl;
    cin >> w >> h;
  }
  return 0;
}

 vector <vector<int> > randb (vector <vector<char> >tile,vector <vector<int> > canmove,int si,int sj,int w,int h){
   if( si+1 < h && tile[si+1][sj] == '.'  && canmove[si+1][sj] == 0){
     canmove[si+1][sj] = 1;
     canmove = randb(tile,canmove,si+1,sj,w,h);
   }
   if( si-1 >= 0 && tile[si-1][sj] == '.'  && canmove[si-1][sj] == 0){
     canmove[si-1][sj] = 1;
     canmove = randb(tile,canmove,si-1,sj,w,h);
   }
   if( sj+1 < w && tile[si][sj+1] == '.'  && canmove[si][sj+1] == 0){
     canmove[si][sj+1] = 1;
     canmove = randb(tile,canmove,si,sj+1,w,h);
   }
   if( sj-1 >= 0 && tile[si][sj-1] == '.'  && canmove[si][sj-1] == 0){
     canmove[si][sj-1] = 1;
     canmove = randb(tile,canmove,si,sj-1,w,h);
   }

   return canmove;

}

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

int main(){
  char c;
  int x, y, atx, aty, ind, count = 1;
  std::vector<int> real;
  std::queue<int> q;

  std::cin >> x;
  std::cin >> y;

  while(x != 0 || y != 0){

    real.resize(x*y);

    for(int i = 0; i < y; i++){         //地図の読み込みと＠の座標の格納
      for(int j = 0; j < x; j++){
        std::cin >> c;
        if(c == '.'){

          real[i*x + j] = 1;

        }else if(c == '#'){

          real[i*x + j] = 0;

        }else if(c == '@'){

          real[i*x + j] = -1;
          atx = j;//atx と aty は＠の座標を意味している
          aty = i;

        }else{

          std::cout << "unexpected char input!" << std::endl;
          return 0;

        }
      }
    }

    //＠を起点にして探索を開始する。

    q.push(atx + aty * x);

    while( !q.empty() ){

      ind = q.front();
      q.pop();


      if( ind%x != 0){//左をチェック 左端でなければ
        if(real[ ind-1 ] == 1 ){

          real[ ind-1 ] = -1;
          q.push( ind-1 );
          count++;
        }
      }

      if( ind%x != x-1 ){//右をチェック 右端でなければ
        if(real[ ind+1 ] == 1){

          real[ ind+1 ] = -1;
          q.push( ind+1 );
          count++;
        }
      }

      if( ind-x > 0 ){//上をチェック 上端でなければ
        if(real[ ind-x ] == 1){

          real[ ind-x ] = -1;
          q.push( ind-x );
          count++;
        }
      }

      if( ind+x < x * y){//下をチェック 下端でなければ
        if(real[ ind+x ] == 1){

          real[ ind+x ] = -1;
          q.push( ind+x );
          count++;
        }
      }

    }

    std::cout << count << std::endl;

/*
    for(int i = 0; i < y;i++){
      for(int j = 0; j < x; j++){
        std::cout << real[i*x + j];
      }
      std::cout << std::endl;
    }
//*/
    std::cin >> x;
    std::cin >> y;
    count = 1;
  }

  return 0;
}