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<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	while(1){
		int i,j,k,w,h,a;
		char c[20][20];
		cin>>w>>h;
		if(w==0&&h==0)break;
		for(i=0;i<20;i++){
			for(j=0;j<20;j++){
				c[i][j]='\0';
			}
		}
		
		
		for(i=0;i<h;i++){
			cin>>c[i];
		}
		for(k=0;k<=w*h;k++){
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(c[i][j]=='.'){
						if(i!=h-1){
							if(c[i+1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=w-1){
							if(c[i][j+1]=='@'){
								c[i][j]='@';
							}
						}
						if(i!=0){
							if(c[i-1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=0){
							if(c[i][j-1]=='@'){
								c[i][j]='@';
							}
						}
					}	
				}
			}
		}
		

		a=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(c[i][j]=='@')a++;	
			}
		}
		cout<<a<<endl;
	}

    return 0;
}

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

int W,H;
int count=0;

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


vector<vector<char> > M;

void go(int x,int y){
	if(x<0 || y<0 || x>=W || y>=H) return;
	if(M[y][x]=='.' || M[y][x]=='@'){
		count++;
		M[y][x]='#';
		for(int r=0;r<4;r++){
			go(x+dx[r],y+dy[r]);
		}
	}
}

void solve(){
	count=0;

	M.clear();
	M.resize(H,vector<char>(W));

	int sx,sy;
	for(int y=0;y<H;y++){
		for(int x=0;x<W;x++){
			char t;
			cin>>t;
			M[y][x]=t;
			if(t=='@'){
				sx=x;sy=y;
			}
		}
	}

	go(sx,sy);
	cout<<count<<endl;

}


int main(){
	while(cin>>W>>H){
		if(W==0) return 0;
		solve();
	}
}

C++: #include <string>
#include <iterator>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

string GetStr()
{
	string str;
	getline(cin,str);
	return str;
}

vector<int> GetIntVector()
{
	string str;
	getline(cin,str);
	istringstream line( str );

	istream_iterator<int> iit(line);
	istream_iterator<int> iit_eof;

	vector<int> ret;

	for(;iit != iit_eof; iit++){
		ret.push_back(*iit);
	}

	return ret;
}

int counter;

void GoNext(vector<string>& lines,int hh,int hw)
{
	counter++;
	lines[hh][hw] = '#';

	if(hw > 0 && lines[hh][hw-1] != '#')
		GoNext(lines,hh,hw-1);

	if(hw < (int)lines[hh].size() - 1 && lines[hh][hw+1] != '#')
		GoNext(lines,hh,hw+1);

	if(hh > 0 && lines[hh-1][hw] != '#')
		GoNext(lines,hh-1,hw);

	if(hh < (int)lines.size() - 1 && lines[hh+1][hw] != '#')
		GoNext(lines,hh+1,hw);
}

void solve(int w,int h)
{
	vector<string> lines;
	for(int i = 0; i < h; i++){
		lines.push_back(GetStr());
	}

	int humanw,humanh = -1;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(lines[i][j] == '@'){
				humanh = i; humanw = j;
				break;
			}
		}
		if(humanh != -1) break;
	}

	counter = 0;

	GoNext(lines,humanh,humanw);

	cout << counter <<endl;
}

void solve1130()
{
	vector<int> v = GetIntVector();
	while(v[0] != 0 && v[1] != 0){
		solve(v[0],v[1]);
		 v = GetIntVector();
	}
}


int main()
{
	solve1130();

	return 0;
}

C++: #include<iostream>
#define MAX (256)
using namespace std;

int N, M;
char field[MAX][MAX];
int sx, sy;
int ans = 0;

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

void dfs (int x, int y){
	if(0 <= x && x < N && 0 <= y && y < M && field[x][y] == '.'){
		field[x][y] = '#';
		ans++;
		
		for(int i =0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			dfs(nx, ny);
		
		}
	}
}

int main(){

	while(1){	
	cin >> M >> N;
	
	if(M == 0 && N == 0) break;
	
	for(int i =0; i < N; i++){
		for(int j =0; j < M; j++){
			cin >> field[i][j];
		}
	}
	
	for(int i =0; i < N; i++){
		for(int j =0; j < M; j++){
			if(field[i][j] == '@'){
				sx = i;
				sy = j;
				field[sx][sy] = '.';
			}
		}
	}
		
	dfs(sx, sy);
	
	cout << ans << endl;
	}
	return 0;
}