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;

int serch(int,int);
char tile[20][20];
int W,H;

int main(){
	int posx,posy;

	while(1){
		cin >> W >> H;
		if(W==0&&H==0) break;

		//^CÇÝÝ
		for(int j=0;j<H;j++){
			for(int i=0;i<W;i++){
				cin >> tile[i][j];
			}
		}

		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				if(tile[i][j]=='@'){
					posx=i,posy=j;
				}
			}
		}

		cout << serch(posx,posy)+1 << endl;
		for(int j=0;j<20;j++){
			for(int i=0;i<20;i++){
				tile[i][j]='#';
			}
		}

	}

	return 0;
}

int serch(int x,int y){
	//cout << "x=" << x << " " << "y=" << y << endl;
	int cnt=0;
	if(x==0&&y==0){
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
		}
		//cout << "x==y==0" << endl;
	}else if(x==W&&y==0){
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
		}
		//cout << "x==W&&y==0" << endl;
	}else if(x==0&&y==H){
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
		}
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
		}
		//cout << "x==0&&y==H" << endl;
	}else if(x==W&&y==H){
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
		}
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
		}
		//cout << "x==W&&y==H" << endl;
	}else if(x==0){
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
		}
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
		}
		//cout << "x==0" << endl;
	}else if(x==W){
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
		}
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
		}
		//cout << "x==W" << endl;
	}else if(y==0){
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
		}
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
		}
		//cout << "y==0" << endl;
	}else if(y==H){
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
		}
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
		}
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
		}
		//cout << "y==H" << endl;
	}else {
		if(tile[x-1][y]=='.'){
			tile[x-1][y]='@';
			cnt++;
			cnt = cnt + serch(x-1,y);
			//cout << "a---------------a" << endl;
		}
		if(tile[x+1][y]=='.'){
			tile[x+1][y]='@';
			cnt++;
			cnt = cnt + serch(x+1,y);
			//cout << "b---------------b" << endl;
		}
		if(tile[x][y-1]=='.'){
			tile[x][y-1]='@';
			cnt++;
			cnt = cnt + serch(x,y-1);
			//cout << "c---------------c" << endl;
		}
		if(tile[x][y+1]=='.'){
			tile[x][y+1]='@';
			cnt++;
			cnt = cnt + serch(x,y+1);
			//cout << "d---------------d" << endl;
		}
	}
	//cout << endl;
	//for(int j=0;j<H;j++){
	//	for(int i=0;i<W;i++){
	//		cout << tile[i][j];
	//	}
	//	cout << endl;
	//}
	//
	return cnt;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<vector<char> > field;

int search(field &f, int x, int y)
{
    if(f[y][x]=='#') return 0;
    f[y][x] = '#';
    int res = 1;
    if(f[y][x-1]!='#') res += search(f, x-1, y);
    if(f[y][x+1]!='#') res += search(f, x+1, y);
    if(f[y-1][x]!='#') res += search(f, x, y-1);
    if(f[y+1][x]!='#') res += search(f, x, y+1);
    return res;
}

int main()
{
    int w, h;
    while(cin >> w >> h, w|h)
    {
        field f(h+2, vector<char>(w+2, '#'));
        int sx, sy;
        for(int y=0; y<=h+1; y++) f[y].assign(w+2, '#');
        for(int y=1; y<=h; y++)
        {
            string ln;
            cin >> ln;
            for(int i=0; i<w; i++)
            {
                f[y][i+1] = ln[i];
                int spos = ln.find('@');
                if(spos>=0)
                {
                    sy = y;
                    sx = spos + 1;
                }
            }
        }
        cout << search(f, sx, sy) << endl;
    }
}

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

typedef pair<int,int> pii;

int main(void){
	int h,w;
	queue<pii> s;
	string m[21];
	while(cin>>w>>h,w||h){
		for(int i=0;i<h;i++)cin>>m[i];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(m[i][j]=='@'){
					s.push(pii(i,j));
					i=j=999;
				}
			}
		}
		int c=0;
		while(!s.empty()){
			pii a=s.front();s.pop();
			int i=a.first;
			int j=a.second;
			if(!(0<=i&&i<h&&0<=j&&j<w))continue;
			if(m[i][j]=='#')continue;
			c++;
			m[i][j]='#';
			s.push(pii(i+1,j));
			s.push(pii(i-1,j));
			s.push(pii(i,j+1));
			s.push(pii(i,j-1));
		}
		cout<<c<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int w,h;
int count; 
int dx[4]={1,0,-1,0};int dy[4]={0,1,0,-1};
char board[100][100];
void dfs(int x,int y){
       count++;
       board[y][x]='#';
    for(int i=0;i<4;i++){
      int nx=x+dx[i];int ny=y+dy[i];
      if(nx>=0&&nx<w&&ny>=0&&ny<h&&board[ny][nx]=='.'){
          dfs(nx,ny);
      }
    }
}
int main(){
	while(1){
  cin>>w>>h;
  if(w==0&&h==0) break;
  count=0;
  for(int k=0;k<h;k++){
    cin>>board[k];
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(board[i][j]=='@'){
         dfs(j,i);
      }
    }
  }
  cout<<count<<endl;
}
  return 0;
}