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

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

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

void dfs(int x, int y){
    for(int i=0; i<4; i++){
        int xx = x + dx[i];
        int yy = y + dy[i];
        if(0 <= xx && xx < w && 0 <= yy && yy < h && fie[yy][xx] == '.'){
            fie[yy][xx] = '@';
            dfs(xx,yy);
        }
    }
}

int main(){
    while(cin >> w >> h , w||h){
        int sx,sy;
        for(int i=0; i<h; i++){
            cin >> fie[i];
            for(int j=0; j<w; j++){
                if(fie[i][j] == '@'){
                    sx = j; sy = i;
                }
            }
        }
        dfs(sx,sy);
        int ans = 0;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(fie[i][j] == '@') ans++;
            }
        }
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF					INT_MAX
#define LLINF					LLONG_MAX
#define DEBUG					false
 
typedef long long				ll;
typedef pair <int, int> ii;

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

int main() {
	
	int w, h;
	
	while(cin >> w >> h, w, h){
		vector<string> mp(h);
		//vector<vector<bool> > used(h, vector<int>(w));
		rep(i, h) cin >> mp[i];
		
		int sx, sy;
		rep(i, h){
			rep(j, w) if(mp[i][j] == '@'){
				sx = j;
				sy = i;
			}
		}
		
		queue<ii> qu;
		qu.push(make_pair(sx, sy));
		
		int ans = 0;
		while(!qu.empty()){
			ii tmp = qu.front();
			qu.pop();
			ans++;
			
			
			rep(i, 4){
				int nx = tmp.first + dx[i];
				int ny = tmp.second + dy[i];
			
				if(nx < 0 || w <= nx) continue;
				if(ny < 0 || h <= ny) continue;
				
				if(mp[ny][nx] == '.'){
					qu.push(make_pair(nx, ny));
					mp[ny][nx] = '#';	
				}
				
			}
			
			
		}
		
		cout << ans << endl;
		
		
	}
	
	
	
	return 0;
}

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

bool debug=true;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
char d[21][21];

void init(){
  for(int i=0;i<21;i++)for(int j=0;j<21;j++)d[i][j]='#';
}

int dfs(int sx,int sy){
  int cnt=0;
  queue<int>que;
  que.push(sx);que.push(sy);
  while(que.size()){
    int x=que.front();que.pop();
    int y=que.front();que.pop();
    for(int i=0;i<4;i++){
      if(d[y+dy[i]][x+dx[i]]=='.'){
	que.push(x+dx[i]);que.push(y+dy[i]);
	d[y+dy[i]][x+dx[i]]='#';
	cnt++;
      }
    }
  }
  return cnt+1;
}

int main(){
  int w,h;
  
  while(1){
    cin>>w>>h;
    if(w==0&&h==0)break;
    init();
    int x,y;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>d[i][j];
	if(d[i][j]=='@'){
	  x=j;y=i;
	}
      }
    }
    cout<<dfs(x,y)<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <complex>

using namespace std;

typedef complex<int> P;

int main() {
	int W, H;
	while ( cin >> W >> H, W || H ) {
		int m[20][20], sx, sy;
		for (int y = 0; y < H; ++y) {
			string str; cin >> str;
			for (int x = 0; x < W; ++x) {
				m[y][x] = str[x] == '#' ? 0 : 1;
				if (str[x] == '@') {
					sx = x, sy = y;
				}
			}
		}
		int ans = 0;
		queue<P> Q; Q.push( P(sx, sy) );
		while ( !Q.empty() ) {
			P p = Q.front(); Q.pop();
			int y = p.imag(), x = p.real();
			if (y < 0 || y >= H || x < 0 || x >= W) continue;
			if ( m[y][x] == 0 ) continue;
			m[y][x] = 0;
			++ans;
			
			Q.push( P(x+1, y) );
			Q.push( P(x-1, y) );
			Q.push( P(x, y-1) );
			Q.push( P(x, y+1) );
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<string>

#define rep(i,n) for(int i=0; i<n; i++)

int w,h;
std::string f[20];
int cnt;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

void rec(int x, int y){
	int mx, my;

	f[y][x] = '#';
	cnt++;

	rep(i,4){
		mx = x + dx[i];
		my = y + dy[i];

		if(mx < 0 || mx >= w)continue;
		if(my < 0 || my >= h)continue;
		if(f[my][mx] != '.')continue;
		rec(mx, my);
	}
}




int main(){
	while(std::cin >> w >> h, (w||h)){
		rep(i,h){
			std::cin >> f[i];
		}
		cnt = 0;
		rep(i,h){
			rep(j,w){
				if(f[i][j] == '@')rec(j,i);
			}
		}
		std::cout << cnt << std::endl;
	}
	return 0;
}