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++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1130&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int W,H;

void dfs(vector<string> &field, vector<vector<bool> > &move,int now_x, int now_y)
{
	int dx[4] = {1,0,-1,0};
	int dy[4] = {0,1,0,-1};

	if(now_x < 0 || now_x >= W || now_y < 0 || now_y >= H){ return; }
	
	if(field[now_y][now_x] == '#'){ return; }

	if(move[now_y][now_x]){ return; }

	move[now_y][now_x] = true;

	rep(i,4){
		dfs(field, move, now_x+dx[i], now_y+dy[i]);
	}

	return;
}

int main() {

	while(cin >> W >> H && W && H)
	{

		vector<string> field(H);
		vector<vector<bool> > move(H, vector<bool>(W,false));

		rep(y,H){
			cin >> field[y];
		}

		pair<int, int> start;
		rep(y,H){
			rep(x,W){
				if(field[y][x] == '@'){start = make_pair(x,y);}
			}
		}

		
		dfs(field, move, start.first, start.second);

		int count=0;
		rep(y,H){
			rep(x,W){
				if(move[y][x]){ count++; }
			}
		}

		cout << count << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char grid[100][100];
int w,h;
int ans=0;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
bool searched[100][100];
int a=0,b=0;

bool inrange(int x,int y){
  if(x<0||y<0||x>=h||y>=w) return false;
  else return true;
}

void search(int x,int y){
  if((grid[x][y]=='.'||grid[x][y]=='@')&&searched[x][y]==false&&inrange(x,y)){
	searched[x][y]=true;
	ans++;
	//	cout <<x <<' '<<y << endl;
	  REP(i,4) {
	  search(x+dx[i],y+dy[i]);
	}
  }
}

int main(){
  while(1){
	cin >> w >> h;
	if(w==0&&h==0) break;
	ans = 0;
	REP(i,h){
	  REP(j,w){
		cin >> grid[i][j];
		searched[i][j]=false;
		if(grid[i][j]=='@'){
		  a=i;
		  b=j;
		}
	  }
	}
	search(a,b);

	cout<<ans<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
char mp[22][22];
int cnt = 0;
int d_x[] = {0,1,0,-1};
int d_y[] = {1,0,-1,0};
int W,H;

void dfs(int x,int y){
  mp[y][x] = '#';
  cnt++;
  for(int d = 0;d<4;d++){
    int nx = x+d_x[d],ny = y+d_y[d];
    if((nx>=0)&&(ny>=0)&&(ny<H)&&(nx<W)&&(mp[ny][nx] == '.')){
      dfs(nx,ny);
    }
  }
}
int main(){
  cin >>W>>H;

  while((W!=0)&&(H!=0)){
    cnt = 0;
    for(int i = 0;i<22;i++){
      for(int j = 0;j<22;j++){
        mp[i][j] = '#';
      }
    }
    for(int i = 0;i<H;i++){
      for(int j = 0;j<W;j++){
        cin >>mp[i][j];
      }
    }
    for (int y = 0; y < H; y++){
      for (int x = 0; x < W; x++) {
        if (mp[y][x] == '@') {
          dfs(x, y);
        }
      }
    }
    cout <<cnt<<endl;
    cin >>W>>H;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int mp[21][21];
  int w,h;
  int x[4]={1,-1,0,0};
  int y[4]={0,0,1,-1};
  int m;
  bool b;
  char s;
  int ans;
  while(1){
    cin>>w>>h;
    if(w==0 && h==0) break;
    ans=0;
    for(int i=0;i<21;i++){
      for(int j=0;j<21;j++){
	mp[i][j]=0;
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>s;
	if(s=='#') mp[i][j]=1;
	else if(s=='@') mp[i][j]=2;
      }
    }
    b=true;
    while(b){
      b=false;
      for(int i=0;i<h;i++){
	for(int j=0;j<w;j++){
	  if(mp[i][j]==2){
	    /*for(int k=0;k<4;k++){*/
	      if(mp[i+1][j]==0){
		mp[i+1][j]=2;
		b=true;
	      }
	      if(mp[i-1][j]==0){
		mp[i-1][j]=2;
		b=true;
	      }
	      if(mp[i][j+1]==0){
		mp[i][j+1]=2;
		b=true;
	      }
	      if(mp[i][j-1]==0){
		mp[i][j-1]=2;
		b=true;
	      }
	  }
	}
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	/*cout<<mp[i][j]<<" ";*/
	if(mp[i][j]==2) ans++;
      }
      /* cout<<endl;*/
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
queue<pair<int,int> > M;
int W,H;
int q[20+5][20+5] = {};	
char p[20+5][20+5];
int counter;
int x,y;
int main() {
	while(cin >> W >> H && W != 0){
		counter = 0;
		for (int i = 1; i <= H; i++){
			for (int j = 1; j <= W; j++){
				cin >> p[i][j];
				if (p[i][j] == '@' ){
					M.push(make_pair(i,j));
					counter = 1;
					q[i][j] = 1;
				}
			}
		}
		while(!M.empty()){
			x = M.front().first;
			y = M.front().second;
			M.pop();
			for (int k = 0; k <= 3; k++)
			{		
				if (p[x+dx[k]][y+dy[k]] == '.' && q[x+dx[k]][y+dy[k]] == 0)
				{
					M.push(make_pair(x+dx[k], y+dy[k]));
					q[x+dx[k]][y+dy[k]] = 1;
					counter += 1;
				}
			}
		}
		cout << counter << endl;
	}
}