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>
#include <vector>
using namespace std;

const int MAX_N = 20;

int W, H;
int sx, sy;                 // ?????????????????§?¨?
int dx[4] = {-1, 0, 0, 1};
int dy[4] = { 0,-1, 1, 0};

bool isVisited[MAX_N][MAX_N];

int dfs(const vector<vector<char>>& masu, int x, int y) {
    if (!isVisited[y][x] && masu[y][x] != '#') {
        isVisited[y][x] = true;

        int ret = 1;
        for (int i = 0; i < 4; i++) {
            if (0 <= x+dx[i] && x+dx[i] < W && 0 <= y+dy[i] && y+dy[i] < H) {
                // cout << "#: x=" << x+dx[i] << ", y=" << y+dx[i] << endl;
                ret += dfs(masu, x+dx[i], y+dy[i]);
            }
        }

        return ret;
    }
    return 0;
}

int main(void) {

    while (cin >> W >> H, W) {
        for (int i = 0; i < MAX_N; i++) {
            for (int j = 0; j < MAX_N; j++) {
                isVisited[i][j] = false;
            }
        }

        vector<vector<char>> masu(H, vector<char>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> masu[i][j];
                if (masu[i][j] == '@') {
                    sx = j;
                    sy = i;
                }
            }
        }

        cout << dfs(masu, sx, sy) << endl;
    }

    return 0;
}

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

using namespace std;

string a[21];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int cnt, X, Y;

void dfs(int y, int x){
  if( y < 0 || Y <= y || x < 0 || X <= x || a[y][x] == '#') return;
  a[y][x] = '#';
  cnt++;
  for(int i = 0; i < 4; i++)
    dfs(y + dy[i], x + dx[i]);
}

int main(){
  while(cin >> X >> Y, X != 0 || Y != 0) {
    int sx = 21, sy;
    for(int i = 0; i < Y; i++){
      cin >> a[i];
      if(sx == 21)
	for(int j = 0; j < X; j++)
	  if(a[i][j] == '@') sy = i, sx = j;
    }
    cnt = 0;
    dfs(sy, sx);
    
    cout << cnt << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

int W, H;
char board[30][30];
bool visited[30][30];

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

void dfs(int x, int y) {
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (board[nx][ny] == '#') continue;
      if (visited[nx][ny]) continue;
      visited[nx][ny] = true;
      dfs(nx, ny);
   }
}

int main() {
   while (cin >> W >> H, W && H) {
      memset(visited, false, sizeof(visited));
      int sx = 0, sy = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            cin >> board[i][j];
            if (board[i][j] == '@') {
               sx = i, sy = j;
            }
         }
      }

      board[sx][sy] = true;
      dfs(sx, sy);

      int cnt = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (visited[i][j]) cnt++;
         }
      }

      cout << cnt << endl;
   }

   return 0;
}

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

int point(int x,int y,int w,int h){
  int s;
  s= x*w*y*h;
  return s;
}

int pointx(int x,int w){
  int s;
  s=x/w;
  return s;
}

int pointy(int x,int w){
  int s;
  s=x%w;
  return s;
}

int main(){
  int w,h;
  w = 1;
  h = 1;
  cin>>w>>h;
  while(w!=0){
    int a[25][25]={};
    int sx,sy;
    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	char s;
	cin>>s;
	if(s=='.'){
	  a[i][j]=1;
	}else if(s=='#'){
	  a[i][j]=-1;
	}else{
	  a[i][j]=2;
	  sx=i;
	  sy=j;
	}
      }
    }

    int d[21][21];
    for(int i=0;i<21;i++){
      for(int j=0;j<21;j++){
	d[i][j]=-1;
      }
    }
    queue<int>q;
    d[sx][sy]=0;
    int str;
    str=point(sx,sy,w,h);
    q.push(str);
    while(! q.empty()){
      int cur =q.front();
      q.pop();
      int x,y;
      x=pointx(cur,w);
      y=pointy(cur,w);
      if(x>=1&&a[x-1][y]==1&&d[x-1][y]==-1){
	d[x-1][y]=0;
	q.push(point(cur-1,y,w,h));
      }
      if(x<=w-2&&a[x+1][y]==1&&d[x+1][y]==-1){
	d[x+1][y]=0;
	q.push(point(cur+1,y,w,h));
      }
      if(y>=1&&a[x][y-1]==1&&d[x][y-1]==-1){
	  d[x][y-1]=0;
	  q.push(point(x,cur-w,w,h));
      }
      if(y<=h-2&&a[x][y+1]==1&&d[x][y+1]==-1){
	d[x][y-1]=0;
	q.push(point(x,cur+w,w,h));
      }
    }

    int t=0;
    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	if(d[i][j]==0){
	  t+=1;
	}
      }
    }
    cout << t<< endl;
    cin>>w>>h;
  }
}

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

char map[20][20];
int W,H;
int cnt;

void fac(int y,int x){
  map[y][x]='#';
  cnt++;
  
  if(map[y+1][x]=='.' && y < H-1)
    fac(y+1,x);
  if(map[y-1][x]=='.' && y > 0)
    fac(y-1,x);
  if(map[y][x+1]=='.' && x < W-1)
    fac(y,x+1);
  if(map[y][x-1]=='.' && x > 0)
    fac(y,x-1);  
}

int main(){
  int i,j;
  int x,y;

  while(1){
    cin >> W >> H;

    if(W+H==0)
      break;
    
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	cin >> map[i][j];
	if(map[i][j]=='@'){
	  x=j; y=i; 
	} //@position      
      }
    }
    
    cnt=0;
    fac(y,x); //release cnt
    cout << cnt << endl;
  }
  return 0;
}