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 <iostream>

char table[100][100];
using namespace std;


int f(int w, int h, int x, int y){
  int ret = 0;
  if(x < 0 || y < 0 || x >= w || y >= h){
    return 0;
  }
  if(table[y][x] == '#'){
    return 0;
  }
  ret = 1;
  table[y][x] = '#';
  ret += f(w, h, x, y + 1);
  ret += f(w, h, x, y - 1);
  ret += f(w, h, x - 1, y);
  ret += f(w, h, x + 1, y);
  return ret;
}

int main(){
  while(true){
    int startX, startY;
    int width, height;
    cin >> width >> height;
    if(width == 0 && height == 0){
      break;
    }
    for(int i = 0; i < height; i++){
      for(int j = 0; j < width; j++){
        cin >> table[i][j];
        if(table[i][j] == '@'){
          //cout << "startX = " << j << " startY = " << i << endl;
          startX = j;
          startY = i;
          table[i][j] = '.';
        }
      }
      
    }
    cout << f(width, height, startX, startY) << endl;
  }
}

C++: #include<bits/stdc++.h>
char n[100][100];int k[100][100],l[100][100],sum,H,W,i,j,m,s;
#define A(B,C) if(k[B][C]!=1){l[B][C]=1;}
int main(){while(true){s=0;memset(l,0,sizeof(l));std::cin>>W>>H;if(W==0){break;}for(i=1;i<=H;i++){for(j=1;j<=W;j++){std::cin>>n[i][j];if(n[i][j]=='.'){k[i][j]=0;}else if(n[i][j]=='@'){k[i][j]=2;l[i][j]=1;}else{k[i][j]=1;}}}
for(i=0;i<2500;i++){for(j=1;j<=H;j++){for(m=1;m<=W;m++){if(l[j][m]==1){A(j-1,m);A(j+1,m);A(j,m-1);A(j,m+1);}}}}
for(j=1;j<=H;j++){for(m=1;m<=W;m++){if(l[j][m]==1){s++;}}}scanf("%d\n",s);}}

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

using namespace std;

struct DataSet{
    int x, y;
    int ax, ay;
    string str;
};

int search(int xSize, int ySize, int x, int y, string& s){
    //cout << '[' << x << ',' << y << ']' << endl;
    int ret = 0;
    int nowPos = x + y * xSize;
    s[nowPos] = '#';
    ++ret;
    
    if(s[nowPos - 1] == '.' && x != 0){
        ret += search(xSize, ySize, x-1, y, s);
    }
    if(s[nowPos + 1] == '.' && x + 1 != xSize){
        ret += search(xSize, ySize, x+1, y, s);
    }
    if(s[nowPos - xSize] == '.' && y != 0){
        ret += search(xSize, ySize,x, y-1, s);
    }
    if(s[nowPos + xSize] == '.' && y + 1 != ySize){
        ret += search(xSize, ySize, x, y+1, s);
    }
    return ret;
}

int main()
{
    vector<DataSet> dataSets;
    char word;
    
    while(cin){
        DataSet dataSet;
        cin >> dataSet.x >> dataSet.y;
        for(int i = 0; i < dataSet.y * dataSet.x; i++){
            cin >> word;
            if(word == '@'){
                dataSet.ax = i % dataSet.x;
                dataSet.ay = i / dataSet.x;
            }
            //cout << line << endl;
            dataSet.str += word;
        }
        dataSets.push_back(dataSet);
    }
    dataSets.pop_back();
    
    //cout << dataSets.back().x << ' ' << dataSets.back().y << endl;
    //cout << dataSets.back().ax << ' ' << dataSets.back().ay << endl;
    //cout << dataSets.back().str;
    
    for(auto dataSet : dataSets){
        if(dataSet.x == 0) continue;
        cout << search(dataSet.x, dataSet.y, dataSet.ax, dataSet.ay, dataSet.str) << endl;
    }
    
    return 0;
}

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

int cnt, a[23][23];  //black : 0, red : 1

void dfs(int x, int y){
    cnt++;
    a[x][y] = 1;
    if(!a[x + 1][y]) dfs(x + 1, y);
    if(!a[x - 1][y]) dfs(x - 1, y);
    if(!a[x][y + 1]) dfs(x, y + 1);
    if(!a[x][y - 1]) dfs(x, y - 1);
    return;
}

int main(){
    while(1){
        int i, j, w, h, si, sj;
        char in;
        cin >> w >> h;
        if(w == 0)break;
        
        cnt = 0;
        for(i = 0; i <= h + 1; i++){
            a[i][0] = a[i][w + 1] = 1;
        }
        for(j = 0; j <= w + 1; j++){
            a[0][j] = a[h + 1][j] = 1;
        }
       
        i = 1;
        j = 1;
        while(i <= h){
            while(j <= w){
                cin >> in;
                //cout << "~~" << endl;
                if(in == '.'){
                   a[i][j] = 0;
                   j++; 
                }else if(in == '#'){
                    a[i][j] = 1;
                    j++;
                }else if(in == '@'){
                    si = i;
                    sj = j;
                    a[i][j] = 1;
                    j++;
                }
                //cout << j << endl;
            
            
            
            }
            i++;
            j = 1;
        }
        dfs(si, sj);
        cout << cnt << endl;
    }
    return 0;
}