Go: package main

import (
	"bufio"
	"encoding/json"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

var strByColor = map[Color]string{
	ColorBlack: "black",
	ColorRed:   "red",
}

func (c Color) String() string {
	return strByColor[c]
}

type Node struct {
	ID      int
	X, Y    int
	Color   Color
	NextIDs map[int]struct{}
}

func (n *Node) String() string {
	d, _ := json.Marshal(n)
	return string(d)
}

type Map struct {
	Width, Height int
	Nodes         map[int]*Node
}

func (m *Map) GetByID(id int) *Node {
	return m.Nodes[id]
}

func (m *Map) Get(x, y int) *Node {
	return m.Nodes[m.getID(x, y)]
}

func (m *Map) SetColor(x, y int, c Color) {
	m.Nodes[m.getID(x, y)].Color = c
}

func (m *Map) getID(x, y int) int {
	return x + y*m.Width
}

func (m *Map) init() {
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			id := m.getID(x, y)
			m.Nodes[id] = &Node{ID: id, X: x, Y: y}
		}
	}
	for x := 1; x <= m.Width; x++ {
		for y := 1; y <= m.Height; y++ {
			nextIDs := map[int]struct{}{}
			if x > 1 {
				nextIDs[m.getID(x-1, y)] = struct{}{}
			}
			if x < m.Width {
				nextIDs[m.getID(x+1, y)] = struct{}{}
			}
			if y > 1 {
				nextIDs[m.getID(x, y-1)] = struct{}{}
			}
			if y < m.Height {
				nextIDs[m.getID(x, y+1)] = struct{}{}
			}
			m.Get(x, y).NextIDs = nextIDs
		}
	}
}

func NewMap(w, h int) *Map {
	m := &Map{Width: w, Height: h, Nodes: map[int]*Node{}}
	m.init()
	return m
}

type Searcher struct {
	Map        *Map
	queue      []*Node
	touchedIDs map[int]struct{}
	visitedIDs map[int]struct{}
}

func NewSearcher(m *Map) *Searcher {
	return &Searcher{
		Map:        m,
		queue:      []*Node{},
		touchedIDs: map[int]struct{}{},
		visitedIDs: map[int]struct{}{},
	}
}

func (s *Searcher) Search(start *Node) {
	s.enqueue(start)

	for {
		if len(s.queue) == 0 {
			break
		}
		for nextID := range s.dequeue().NextIDs {
			n := s.Map.GetByID(nextID)
			if n.Color == ColorRed || s.hasTouched(n) {
				continue
			}
			s.enqueue(n)
		}
	}
}

func (s *Searcher) VisitedNodeCount() int {
	return len(s.visitedIDs)
}

func (s *Searcher) hasTouched(n *Node) bool {
	_, ok := s.touchedIDs[n.ID]
	return ok
}

func (s *Searcher) enqueue(n *Node) {
	s.queue = append(s.queue, n)
	s.touchedIDs[n.ID] = struct{}{}
}

func (s *Searcher) dequeue() *Node {
	n := s.queue[0]
	s.queue = s.queue[1:]
	s.visitedIDs[n.ID] = struct{}{}
	return n
}

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])

		m := NewMap(w, h)

		// Set colors
		var start *Node
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					m.SetColor(i+1, y, ColorBlack)
					if c == '@' {
						start = m.Get(i+1, y)
					}
				case '#':
					m.SetColor(i+1, y, ColorRed)
				}
			}
		}

		// Search
		s := NewSearcher(m)
		s.Search(start)
		fmt.Println(s.VisitedNodeCount())
	}
}

C++: #include<cstdio>
#include<cstring>
using namespace std;

int w,h,sx,sy,visit[100][100],cnt;
char s[100][100];

void dfs(int x,int y){
    visit[x][y]=1;
    if(x>0&&s[x-1][y]=='.'&&!visit[x-1][y]){
        dfs(x-1,y);
    }
    if(x<h-1&&s[x+1][y]=='.'&&!visit[x+1][y]){
        dfs(x+1,y);
    }
    if(y>0&&s[x][y-1]=='.'&&!visit[x][y-1]){
        dfs(x,y-1);
    }
    if(y<w-1&&s[x][y+1]=='.'&&!visit[x][y+1]){
        dfs(x,y+1);
    }
}

int main(){
    scanf("%d %d",&w,&h);
    while(w&&h){
        for(int i=0;i<h;i++){
            scanf("%s",s[i]);
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j]=='@'){
                    sx=i;
                    sy=j;
                }
                visit[i][j]=0;
            }
        }
        dfs(sx,sy);
        cnt=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cnt+=visit[i][j];
            }
        }
        printf("%d\n",cnt);
        scanf("%d %d",&w,&h);
    }
}

C++: //00
#include<iostream>
#include<queue>
#include<utility>

using namespace std;

int main(){
  for(int W,H;cin>>W>>H,W|H;){
    bool g[20][20];
    queue<pair<int,int> > que;
    for(int y=0;y<H;y++){
      for(int x=0;x<W;x++){
	char c;
	cin>>c;
	g[y][x]=c=='.';
	if(c=='@'){
	  que.push(make_pair(y,x));
	}
      }
    }
    int ans=0;
    while(!que.empty()){
      ans++;
      int y=que.front().first;
      int x=que.front().second;
      que.pop();
      int dy[]={0,1,0,-1};
      int dx[]={1,0,-1,0};
      for(int i=0;i<4;i++){
	int ny=y+dy[i];
	int nx=x+dx[i];
	if(0<=ny&&ny<H&&0<=nx&&nx<W&&g[ny][nx]){
	  que.push(make_pair(ny,nx));
	  g[ny][nx]=false;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int dfs(int x,int y,int f[32][32]) {
	int n = 1;
	f[x][y] = 0;
	if (f[x + 1][y] == 1)
		n += dfs(x + 1, y, f);
	if (f[x - 1][y] == 1)
		n += dfs(x - 1, y, f);
	if (f[x][y + 1] == 1)
		n += dfs(x, y + 1, f);
	if (f[x][y - 1] == 1)
		n += dfs(x, y - 1, f);
	return n;
}


int main()
{
	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0 && h == 0)break;
		int floor[32][32] = {};
		int startX = 0;
		int startY = 0;
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				char c;
				cin >> c;
				if (c == '.' || c == '@') {
					floor[i][j] = 1;
					if (c == '@') {
						startX = i;
						startY = j;
					}
				}
				else if (c == '#')floor[i][j] = 0;
			}
		}
		int cnt = dfs(startX, startY, floor);
		cout << cnt << endl;
	}
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

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

int dfs(vector< vector<bool> > &m, int x, int y){
	if(!m[x][y])return 0;
	int ret = 1;
	m[x][y] = false;
	for(int i = 0; i < 4; i++){
		ret += dfs(m, x+dx[i], y+dy[i]);
	}
	return ret;
}

int main(){
	while(true){
		int h,w; cin >> w >> h;
		if(h == 0)break;
		pair<int,int> s;
		vector< vector<bool> > m(h+2, vector<bool>(w+2, false));
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				char c; cin >> c;
				if( c == '.'){
					m[i+1][j+1] = true;
				}
				else if( c == '@'){
					m[i+1][j+1] = true;
					s = make_pair(i+1, j+1);
				}
			}
		}
		int ans = dfs(m,s.first, s.second);
		cout << ans << endl;
	}
	return 0;
}

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

typedef pair<int, int> pxy;

char map[20][20];

int W, H, start_x, start_y, ans = 0;

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

void dfs(int sx, int sy)
{
  stack<pxy> s;
  s.push(pxy(sx, sy));
  while(!s.empty()){
    int x, y;
    x = s.top().first;
    y = s.top().second;
    s.pop();
    if(map[x][y] != '#'){
      ans++;
      map[x][y] = '#';
      for(int i = 0; i < 4; i++){
	int next_x = x + dx[i], next_y = y + dy[i];
	if(next_x < W && next_x >= 0 && next_y < H && next_y >= 0){
	  s.push(pxy(next_x, next_y));
	}
      }
    }
  }
}

int main()
{
  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0){
      break;
    }else{
      for(int i = 0; i < H; i++){
	for(int j = 0; j < W; j++){
	  cin >> map[j][i];
	  if(map[j][i] == '@'){
	    start_x = j;
	    start_y = i;
	  }
	}
      }
      dfs(start_x, start_y);
      cout << ans << endl;
      ans = 0;
    }
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
 
int w, h;
 
int dfs(int y, int x, vector<string> &v){
  int my[] = {-1,0,1,0};
  int mx[] = {0,-1,0,1};
  int ret = 1;
  REP(i, 4){
    int ny = y + my[i], nx = x + mx[i];
    if(0<=ny&&ny<h&&0<=nx&&nx<w && v[ny][nx] == '.'){
      v[ny][nx] = '#';
      ret += dfs(ny, nx, v);
    }
  }
  return ret;
}
 
int main(){
  while(cin >>w >>h && w){
    vector<string> v(h);
    REP(i, h) cin >>v[i];
    REP(i, h) REP(j, w) if(v[i][j] == '@') cout <<dfs(i, j, v) <<endl;
  }
  return 0;
}