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<stdio.h>

int main(void){
  int W,H;
  char room[20][20];
  int i,j,k;
  int count;
  scanf("%d %d",&W,&H);
  while(!(W==0&&H==0)){
    for(i=0;i<H;i++){
      scanf("%s",room[i]);
    }
    for(i=0;i<W*H;i++){
      for(j=1;j<H;j++){
	for(k=0;k<W;k++){
	  if(room[j][k]!='#' && room[j-1][k]=='@'){
	    room[j][k]='@';
	  }
	}
            }
      for(j=0;j<H;j++){
	for(k=1;k<W;k++){
	  if(room[j][k]!='#' && room[j][k-1]=='@'){
	    room[j][k]='@';
	  }
	}
      }
      for(j=0;j<H-1;j++){
	for(k=0;k<W;k++){
	  if(room[j][k]!='#' && room[j+1][k]=='@'){
	    room[j][k]='@';
	  }
	}
      }
      for(j=0;j<H;j++){
	for(k=0;k<W-1;k++){
	  if(room[j][k]!='#' && room[j][k+1]=='@'){
	    room[j][k]='@';
	  }
	}
      }
    }
    count=0;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(room[i][j]=='@'){
	  count++;
	}
      }
    }
    printf("%d\n",count);
    scanf("%d %d", &W,&H);
  }
  return 0;
}

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

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

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

int W, H;
char B[30][30];

int dfs(int y, int x) {
   int ret = 1;
   B[y][x] = '#';
   rep (i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx >= 0 && nx < W && ny >= 0 && ny < H && B[ny][nx] == '.') ret += dfs(ny, nx);
   }
   return ret;
}

int main() {
   while (cin >> W >> H, W) {
      rep (i, H) cin >> B[i];
      int sy = 0, sx = 0;
      rep (i, H) rep (j, W) if (B[i][j] == '@') sy = i, sx = j;
      cout << dfs(sy, sx) << endl;
   }
   
   return 0;
}

C++: #include <iostream>
using namespace std;
int cnt,w,h;
string s[21];
void check(int i,int j){
	if(s[i][j]=='#')return;
	cnt++;
	s[i][j]='#';
	if(i>0)check(i-1,j);
	if(i<h-1)check(i+1,j);
	if(j>0)check(i,j-1);
	if(j<w-1)check(i,j+1);
}


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

	}
}

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

int G[410];
int R[410][410];
int D[410];
int bfs(int src,int num);

int main() {
	int W,H,root;
	char c;


	while (true) {
		for(int i=0;i<400;i++) {
			for(int j=0;j<400;j++) {
				R[i][j] = 0;
			}
		}
		for(int i=0;i<400;i++) {
			G[i] = 0;
		}
		for(int i=0;i<400;i++) {
			D[i] = 100;
		}
		cin >> W >> H;
		if((W == 0) && (H == 0)) break;
		for(int i=0;i<W*H;i++) {
			cin >> c;
			if(c == '.') G[i] = 1;
			if(c == '#') G[i] = 0;
			if(c == '@') {
				G[i] = 1;
				root = i;
			}
		}
		for(int i=0;i<W*H;i++) {
			if(G[i] == 1) {
				if(i%W != 0) { //????????????
					if(G[i-1] == 1) {//??????????????? 
						R[i][i-1] = 1;
					}
				}
				if(i%W != W-1) { //????????????
					if(G[i+1] == 1) { //???????????????
						R[i][i+1] = 1;
					}			

				}
				if(i > W-1) { //???????????????
					if(G[i-W] == 1) { //???????????????
						R[i][i-W] = 1;
					}	

				}
				if(i < W*H-W) {//???????????????
					if(G[i+W] == 1){
						R[i][i+W] = 1;
					}	

				}
			}
		}
		cout << bfs(root,W*H) << endl;
	}
	/*
	for(int i=0;i<99;i++) {
		cout << i << " " << G[i] << endl;
	}
	cout << G[98] << endl;
	cout << R[87][98] << endl;
	*/
	
}





int bfs(int src,int num) {
	int cur,dst;
	int count = 1;
	//cerr << "bfs root = " << src << endl;
	queue<int> Q; // ??´??°????????????????????\????????????
	Q.push(src);
	D[src] = 0; // ?????????
	while (!Q.empty()) {
		
		int cur = Q.front(); // ??????????´????????????????
		Q.pop();
// ???????¢??????¨??¨???
		//cerr << cur << " " << D[cur] << endl;
		for (int dst=0;dst<num;dst++) { // ???????????? dst ????????????
			if ((R[cur][dst] == 1) && (D[dst] == 100)) { // cur ?????? dst ??????????????????dst ???????¨??????????
				D[dst] = D[cur]+1; //
				Q.push(dst); // dst ????¨???????????????????
				count++;
			}
		}
	}
	return count;
}

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

void calcCanReach( char c[20][20], int x, int y, int a, int b )
{
    c[b][a] = '@';
    if( b - 1 >= 0 && c[b-1][a] == '.' )
        calcCanReach( c, x, y, a, b - 1 );
    if( b + 1 < y && c[b+1][a] == '.' )
        calcCanReach( c, x, y, a, b + 1 );
    if( a - 1 >= 0 && c[b][a-1] == '.' )
        calcCanReach( c, x, y, a - 1, b );
    if( a + 1 < x && c[b][a+1] == '.' )
        calcCanReach( c, x, y, a + 1, b );
}

int main()
{
    char c[20][20];
    int x, y, a, b;

    while( cin >> x >> y )
    {
        if( x == 0 && y == 0 )
            break;

        for( int i = 0; i < y; i++ )
            for( int j = 0; j < x; j++ )
            {
                cin >> c[i][j];
                if( c[i][j] == '@' )
                {
                    a = j;
                    b = i;
                }
            }
        
        calcCanReach( c, x, y, a, b );

        int cnt = 0;
        for( int i = 0; i < y; i++ )
            for( int j = 0; j < x; j++ )
                if( c[i][j] == '@' )
                    cnt++;
        cout << cnt << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<utility>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define P pair<int, int>

using namespace std;
char field[20][20];
int W, H,sx,sy,nx,ny;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int cnt = 1;


void bfs(){
	queue<P> que;
	que.push(P(sx, sy));

	while (1){

		if (que.empty()){
			break;
		}
		P p = que.front();
		que.pop();
		
		rep(i, 4){
			nx = p.first + dx[i];
			ny = p.second + dy[i];
			if (nx >= 0 && nx < W && 0 <= ny && ny < H && field[ny][nx] == '.'){
				field[ny][nx] = '#';
				que.push(P(nx, ny));
				cnt++;
			}

		}

		/*

		rep(i, H){
			rep(j, W){
				cout << field[i][j];
			}
			cout << endl;
		}

		*/
	}



}





int main(){
	while (1){
		cin >> W >> H;
		if (W == 0 && H == 0){
			break;
		}
		rep(i, H){
			rep(j, W){
				cin >> field[i][j];
				if (field[i][j] == '@'){
					sx = j;
					sy = i;
				}
			}
		}
		bfs();
		cout << cnt << endl;
		cnt = 1;
	}
}