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 <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 10000000
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef pair<int, int> p;
typedef vector<int> v;
typedef vector<int, int> v2;
typedef vector< pair<int, int> > vp;
int dx[4] = {  0, 1, 0, -1 };
int dy[4] = { -1, 0, 1, 0 };

int w, h;
char c[21][21];

int bfs(int y, int x){
	int sum = 1;
	for (int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if (0 <= nx && nx < w && 0 <= ny && ny < h && c[ny][nx] == '.'){
			c[ny][nx] = '#';
			sum += bfs(ny, nx);
		}
	}
	
	return sum;
}

int main(){
	ios::sync_with_stdio(false);

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

		int sx,sy;
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++){
				cin >> c[i][j];
				if (c[i][j] == '@'){
					sy = i;
					sx = j;
				}
			}		

		cout << bfs(sy, sx) << endl;
	}
	return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp Red and Black
//???????????????????£?10?????????????????°20???
#include<iostream>
#include<utility>
#include<queue>
using namespace std;

int tile[21][21]={0};
int d[21][21]={0};
int W,H;
char a;
pair<int,int> person;
int answer=0;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

bool valid(int x,int y){
    return (x>=0 && x<H && y>=0 && y<W && tile[x][y]==1);
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

void bfs(int x,int y){
    queue<pair<int,int>> Q;
    pair<int,int> place = make_pair(x,y);
    Q.push(place);
    ++answer;
    d[x][y]=1;
    //cout<<"visited ("<<x+1<<","<<y+1<<")\n";

    while(!Q.empty()){
        place=Q.front();
        Q.pop();
        for(int i=0;i<4;++i){
            pair<int,int> next=make_pair(place.first+dx[i],place.second+dy[i]);
            if(tile[next.first][next.second]!=0 && d[next.first][next.second]==0 && valid(next.first,next.second)){
                Q.push(next);
                d[next.first][next.second]=1;
                //cout<<"visited ("<<next.first+1<<","<<next.second+1<<")\n";
                ++answer;
            }
        }
    }
}

int main(){
    
    
    while(cin>>W>>H && W!=0){
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                cin>>a;
                if(a=='.'){
                    tile[i][j]=1;
                }
                else if(a=='@'){
                    person.first=i;
                    person.second=j;
                }
            }
        }

        bfs(person.first,person.second);

        cout<<answer<<"\n";
        answer=0;
        Fill(tile,0);
        Fill(d,0);
    }
}

C++: #include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#define GROUND 0
#define WALL 500
#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 < 300; 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;
    //cout << isValidPoint(x+dx,y+dy) << " " << x+dx << y+dy << endl;
    if(isValidPoint(x+dx,y+dy) && step[x+dx][y+dy]==INITIAL){
      //cout << isValidPoint(x+dx,y+dy) << " " << x+dx << y+dy << endl;
      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;
  }
}