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 <cmath>
#include <string>
#include <iomanip>
#define GROUND 0
#define WALL 900
#define INITIAL -1

int count();
void init();
void map();
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(){
  //  char floor[MAX_W][MAX_H];
  //int step[MAX_W][MAX_H];
  
  while(cin >> width >> height && width > 0){
    string line;
    int ix,iy;
    //cout << width << " " << height << endl;
    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;
	}
	//cout << step[j][i];
      }
      //cout << endl;
    }
    //cout << count('.') << count('#') << count('@') << endl;
    for(int k = 0; k < 400; k++){
      //map();
      mark_n_all(k);
      //mark_n(k+1,ix,iy,1,0);
      //cout << endl;
      //map();
      
      //cout << endl;
    }
    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 map(){
  for(int i = 0; i < height; ++i){
    for(int j=0; j < width ; ++j){
      cout << setw(3)<< step[j][i] << " ";
    }
    cout << endl;
  }
}

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){
	//	cout << j <<" " << i << "jツづツづ個値"<< endl;
	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++:   1 #include <bits/stdc++.h>
  2
  3 using namespace std;
  4
  5 int w, h, cnt;
  6 int vx[] = {0, 1, 0, -1};
  7 int vy[] = {1, 0, -1, 0};
  8 char field[20][20];
  9
 10 void solve(int x, int y){
 11
 12     ++cnt;
 13     field[y][x] = '#';
 14
 15     for(int i = 0; i < 4; ++i){
 16
 17         int nx = x + vx[i];
 18         int ny = y + vy[i];
 19
 20         if(nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] == '.')
 21             solve(nx, ny);
 22
 23     }
 24
 25 }
 26
 27 int main(){
 28
 29     int sx, sy;
 30     while(cin >> w >> h){
 31
 32         if(!(w || h)) break;
 33
 34         for(int i = 0; i < h; ++i){
 35             for(int j = 0; j < w; ++j){
 36                 cin >> field[i][j];
 37                 if(field[i][j] == '@'){
 38                     sx = j;
 39                     sy = i;
 40                 }
 41             }
 42         }
 43
 44         cnt = 0;
 45
 46         solve(sx, sy);
 47
 48         cout << cnt << endl;
 49
 50     }
 51
 52 }
~

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

int tansaku(char tile[20][20],int w1,int h1){
    if(tile[w1][h1]!='.'&&tile[w1][h1]!='@')return 0;
    tile[w1][h1]='t';
    return 1+tansaku(tile,w1+1,h1)+tansaku(tile,w1-1,h1)+tansaku(tile,w1,h1+1)+tansaku(tile,w1,h1-1);
}

int main(){
    int w,h;
    int w1,h1; //スタート地点
   // 標準入力
   while(1){
    std::cin >> w;
    std::cin >> h;
    if(w==0&&h==0)break;
    //配列の初期化
    char tile[20][20]={};
    // 配列を取得.
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            std::cin >> tile[j][i];
            if(tile[j][i]=='@'){
                w1=j; h1=i;
            }
        }
    }
    std::cout << tansaku(tile,w1,h1) << std::endl;
   }

    return 0;
}

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

using namespace std;


typedef std::array<uint32_t, 2> Idx;

uint32_t checkAndSetIdx(vector<string>& mp, vector<Idx>& stack, uint32_t i, uint32_t j)
{
    if(i > mp.size()-1 || j > mp.at(0).size()-1)
        return 0;

    if(mp[i][j] == '.'){
        mp[i][j] = 'x';
        Idx e = {i, j};
        stack.push_back(e);
        return 1;
    }

    return 0;
}


int main()
{
    while(1)
    {
        uint32_t h, w;
        cin >> w >> h;

        if(w == 0 && h == 0)
            break;


        Idx iniPos;

        vector<string> mp;
        for(uint32_t i = 0; i < h; ++i){
            mp.push_back([](){string str; cin >> str; return str;}());

            for(uint32_t j = 0; j < w; ++j){
                if(mp[i][j] == '@'){
                    Idx e = {i, j};
                    iniPos = e;
                    mp[i][j] = 'x';
                }
            }
        }


        vector<Idx> stack;
        stack.push_back(iniPos);
        uint32_t cnt = 1;


        while(stack.size() != 0){
            auto nowPos = stack.at(stack.size() - 1);
            stack.pop_back();
            const auto i = nowPos[0],
                       j = nowPos[1];

            cnt += checkAndSetIdx(mp, stack, i+1, j);
            cnt += checkAndSetIdx(mp, stack, i-1, j);
            cnt += checkAndSetIdx(mp, stack, i, j+1);
            cnt += checkAndSetIdx(mp, stack, i, j-1);
        }

        cout << cnt << endl;
    }

    return 0;
}