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 <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  while (1){
    int W, H;
    cin >> W >> H;
    if (W == 0 && H == 0){
      break;
    }
    vector<vector<char>> c(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i <= H; i++){
      for (int j = 1; j <= W; j++){
        cin >> c[i][j];
      }
    }
    int sy, sx;
    for (int i = 1; i <= H; i++){
      for (int j = 1; j <= W; j++){
        if (c[i][j] == '@'){
          sy = i;
          sx = j;
        }
      }
    }
    c[sy][sx] = '.';
    int ans = 0;
    vector<vector<bool>> used(H + 2, vector<bool>(W + 2, false));
    used[sy][sx] = true;
    queue<pair<int, int>> Q;
    Q.push(make_pair(sy, sx));
    while (!Q.empty()){
      int y = Q.front().first;
      int x = Q.front().second;
      Q.pop();
      ans++;
      for (int i = 0; i < 4; i++){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if (!used[y2][x2] && c[y2][x2] == '.'){
          used[y2][x2] = true;
          Q.push(make_pair(y2, x2));
        }
      }
    }
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <string.h>
#include <queue>
#include <map>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	int w, h;
	char world[21][21];
	while(1)
	{
		scanf("%d %d", &w, &h);
		if (w == 0 && h == 0) break;
		int sx = -1, sy = -1;
		int memo[20][20];
		memset(memo, 0, 20 * 20 * sizeof(int));
		REP(i, h)
		{
			scanf("%s", world[i]);
			if (sx == -1)
			{
				REP(j, w)
					if (world[i][j] == '@')
					{
						sx = j;
						sy = i;
					}
			}
		}
		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(sx, sy));
		memo[sy][sx] = 1;
		int area = 0;
		while(!q.empty())
		{
			std::pair<int, int> p = q.front();
			q.pop();
			area++;
			int x = p.first;
			int y = p.second;
			// left
			if (x > 0 && world[y][x-1] == '.' && memo[y][x-1] == 0)
			{
				memo[y][x-1] = 1;
				q.push(make_pair(x-1, y));
			}
			if (x < (w-1) && world[y][x+1] == '.' && memo[y][x+1] == 0)
			{
				memo[y][x+1] = 1;
				q.push(make_pair(x+1, y));
			}
			// up
			if (y > 0 && world[y-1][x] == '.' && memo[y-1][x] == 0)
			{
				memo[y-1][x] = 1;
				q.push(make_pair(x, y-1));
			}
			if (y < (h-1) && world[y+1][x] == '.' && memo[y+1][x] == 0)
			{
				memo[y+1][x] = 1;
				q.push(make_pair(x, y+1));
			}
		}
		printf("%d\n", area);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int W,H,a,b,c;
int t[20][20];
char moji;
int ty[4] = {0,1,0,-1};
int tx[4] = {1,0,-1,0};

void syokika(){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      t[i][j]=0;
    }
  }
  c=0;
}
void visit(int y,int x){
  c++;
  t[y][x]=1;
  int nx,ny;
  for(int i=0;i<4;i++){
    ny=y+ty[i];
    nx=x+tx[i];
    if(0<=ny&&ny<H&&0<=nx&&nx<W&&t[ny][nx]==0){
      visit(ny,nx);
    }
  }
}
int main(){
  while(true){
    syokika();
    cin>>W>>H;
    if(W==0&&H==0)break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>moji;
	if(moji=='.')t[i][j]=0;
	if(moji=='@'){
	  a=i;
	  b=j;
	}
	if(moji=='#')t[i][j]=-1;
      }
    }
    visit(a,b);
    cout<<c<<endl;
  }
  return 0; 
}

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

int standpanel;
char tile[31][31];

void check(int i,int j)
{
	if(tile[i][j]=='.')
	{
		tile[i][j]='#';
		standpanel++;
		check(i-1,j);
		check(i,j-1);
		check(i+1,j);
		check(i,j+1);
		
	}
	
}


int main(){
	int W,H;
	while(cin>> H >> W &&W&&H)
	{
		standpanel = 0;
		for(int i=0;i<=25;i++)for(int j=0;j<=25;j++)tile[i][j]='#';
		int manx,many;
		for(int i=1;i<=W;i++)for(int j=1;j<=H;j++)
		{
			cin >> tile[i][j];
			if(tile[i][j]=='@'){manx = i;many = j;tile[i][j]='.';}
			
		}
		check(manx,many);
		cout << standpanel << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
char map[114][514];
int h, w, ans;
void dfs(int i, int j) {
	ans++;
	map[i][j] = '#';
	if (map[i - 1][j] == '.')dfs(i - 1, j);
	if (map[i + 1][j] == '.')dfs(i + 1, j);
	if (map[i][j - 1] == '.')dfs(i, j - 1);
	if (map[i][j + 1] == '.')dfs(i, j + 1);
	return;
}
int main() {
	while (cin >> h >> w, h, w) {
		ans = 0;
		int x, y;
		for (int i = 0; i < 30; i++)for (int j = 0; j < 30; j++)map[i][j] = '#';
		for (int i = 1; i <= w; i++)for (int j = 1; j <= h; j++) {
			cin >> map[i][j];
			if (map[i][j] == '@') { x = i; y = j; }
		}
		dfs(x, y);
		cout << ans << endl;
	}
}