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<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int w,h;
char fie[23][23];
int check[23][23];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int solve(int x,int y){
  int ret=1;
  check[x][y]=1;
  for(int i=0;i<4;i++){
    if(x+dx[i] < 0 || x+dx[i] >= w || y+dy[i] <0 || y+dy[i] >=h) continue;
    if(fie[x+dx[i]][y+dy[i]]=='.' && check[x+dx[i]][y+dy[i]]==0){
      ret+=solve(x+dx[i],y+dy[i]);
    }
  }
  return ret;
}

main(){
  while(1){
    int x,y;
    cin >> w>>h;
    if(!w || !h) break;
    memset(check,0,sizeof(check));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> fie[j][i];
	if(fie[j][i]=='@'){ x=j;y=i;}
      }
    }
    cout << solve(x,y) << endl;
  }

}

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

void checkboard(void);
void startmove(void);
int checked(int i,int j);

char board[20][20];
int H,W,now[2];

int main(void){
	while(1){
		cin >> H >> W ;
		if (!H && !W) break;
		// count=0;
		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				cin >> board[i][j];
				if(board[i][j]=='@'){
					now[0]=i;
					now[1]=j;
				}
			}
		}
		startmove();
		checkboard();
	}

}


void startmove(void){
	int n;
	do{
		n=0;
		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				if(board[i][j]=='@')
					n+=checked(i,j);
			}
		}

	}while(n);
}

int checked(int i,int j){
	int a=0;
	if(i>=0 && board[i-1][j]=='.'){
		board[i-1][j]='@';
		a=1;
	}
	if(i<W && board[i+1][j]=='.'){
		board[i+1][j]='@';
		a=1;
	}
	if(j>=0 && board[i][j-1]=='.'){
		board[i][j-1]='@';
		a=1;
	}
	if(j<H && board[i][j+1]=='.'){
		board[i][j+1]='@';
		a=1;
	}
	// checkboard();
	return a;
}
void checkboard(void){
		int count=0;
		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				if(board[i][j]=='@') count++; 
				// cout << board[i][j];
			}
		}
			cout << count << endl;

}

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

// #define ll long long
#define vvi vector< 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

int w,h,fx,fy;
char ban[30][30];
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

bool inrange(int px,int py){
  if(px<0||py<0||px>=h||py>=w) return false;
  else return true;
}
int bsearch(int px,int py){
  int cnt = 0;
  REP(i,4){
    int nx = px+ dx[i]; int ny = py+dy[i];
    if(!inrange(nx,ny)) continue;
    if(ban[nx][ny]=='#') continue;
    //cnt++;
    //cout << nx << " " <<ny<<endl;
    if(ban[nx][ny]=='.'){
      ban[nx][ny]='!';
      cnt++;
      cnt += bsearch(nx,ny);
    }
  }
  return cnt;
}

int main(){
  while(1){
    cin >> w >> h;
    if((w==0)&&(h==0)) break;
    REP(i,h){
      char buf[21];
      cin >> buf;
      REP(j,w) {
        ban[i][j] = buf[j];
        if(ban[i][j] == '@'){
          fx = i; fy = j;
        }
      }
    } 
    cout << bsearch(fx,fy)+1 << endl;
  }
  return 0;
}

C++: //??¨??¢?´¢:??±???????????¢?´¢??????????????¢?´¢ 

//??????????????¢?????¬?????????
 
//?????°??¢??°???????????????(?????????)????????\???(?????????)
#include <stdio.h>
#include <queue>
#include <string.h>
using namespace std;	
int W,H;
char c[101][101];
bool visited[100][100];
 
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 	
void compute();//????????????????????£?¨? 
	
int main(){
	
	while(scanf("%d %d",&W,&H),W |H){
	    int i;
		
		for(i=0;i<H;i++){
			scanf(" %s",&c[i][0]);
		}
	}
	return 0;
}

void compute(){
	
	memset(visited,false,sizeof visited);  //{????????????????????????1bit??????????????????1bit????????§?????????} 
	
	queue<int> que;
	int i,j;
	for(j=0;j<W;j++){ 
	 for(i=0;i<H;i++){
	  if(c[i][j]=='@'){
	  	que.push(j+i*H);
	  	visited[i][j]==true;
	  	 break;
	  }
	 }
	}
  int answer=1;
  while(!que.empty()){
	int cur=que.front();
	        que.pop();
	        int x=cur%W;
	        int y=cur/W;
    

  for(i=0;i<4;i++){
	int nx=x+dx[i],ny=y+dy[j];
	
  
  
  if(!(0<=nx&&nx<W&&0<=ny))continue;
  if(c[ny][nx]=='#'||visited[ny][nx])continue;

  que.push(nx+ny*W);
  visited[ny][nx]=true;

    }
   }
 
 }

C++: #include<bits/stdc++.h>
using namespace std;
int W,H;
char fld[20][21];
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
bool used[20][20];
int rec(int y,int x){
    if(fld[y][x]!='.'||used[y][x])return 0;
    used[y][x]=true;
    int ret=0;
    for(int i=0;i<4;i++){
        int ty=y+dy[i],tx=x+dx[i];
        if(ty<0||ty>=H||tx<0||tx>=W)continue;
        ret+=rec(ty,tx);
    }
    return ret+1;
}
int main(){
    while(cin>>W>>H,W||H){
        fill_n(*used,400,false);
        for(int i=0;i<H;i++)cin>>fld[i];

        int sy,sx;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(fld[i][j]!='@')continue;
                sy=i;
                sx=j;
                fld[i][j]='.';
            }
        }

        cout<<rec(sy,sx)<<endl;
    }
    return 0;
}