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>
//#include<windows.h>

int masu[22][22];
int ans=0;
int i,j;

void saiki(int x,int y){
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	printf("%d",ans);
	Sleep(100);
	system("cls");
	*/
	masu[x][y]=1;
	ans++;
	if(masu[x][y-1]==0)saiki(x,y-1);
	if(masu[x+1][y]==0)saiki(x+1,y);
	if(masu[x][y+1]==0)saiki(x,y+1);
	if(masu[x-1][y]==0)saiki(x-1,y);
}

int main(){
	for(;;){
	int W,H;
	int x,y;
	char str[22];
	
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			masu[i][j]=1;
		}
	}
	
	scanf("%d%d", &W, &H);
	if(W == 0){
		break;
	}
	for(i=0;i<H;i++){
		scanf("%s",str);
		for(j=0;j<W;j++){
			if(str[j]=='.')masu[i+1][j+1]=0;
			if(str[j]=='@'){
				x=i+1;
				y=j+1;
				masu[i+1][j+1]=0;
			}
		}
	}
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	printf("%d\n",ans);
	system("cls");
	*/
	saiki(x,y);
	/*
	for(i=0;i<22;i++){
		for(j=0;j<22;j++){
			if(masu[i][j]==0)printf(" ");
			if(masu[i][j]==1)printf("¡");
		}
		puts("");
	}
	*/
	printf("%d\n",ans);
	}
	return 0;
}

C++: #include <stdio.h>

void init(int data[22][22],int w,int h){
	for(int i = 0;i < w+2;i++){
		data[0][i] = 1;
		data[h+1][i] = 1;
	}
	for(int i = 0;i < h;i++){
		data[i+1][0] = 1;
		data[i+1][w+1] = 1;
	}
}

void show(int data[22][22],int w,int h){
	for(int i = 0;i < h+2;i++){
		for(int j = 0;j < w+2;j++){
			printf("%d",data[i][j]);
		}
		printf("\n");
	}
}

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

void count(int data[22][22],int sx,int sy){
	for(int i = 0;i < 4;i++){
		if(data[sy+dy[i]][sx+dx[i]] == 0){
			ans++;
			data[sy+dy[i]][sx+dx[i]] = 2;
			count(data,sx+dx[i],sy+dy[i]);
		}
	}
}

int main(){
	int W,H,sx,sy;
	int data[22][22];
	char str[21];

	while(1){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0){
			break;
		}

		init(data,W,H);
		for(int i = 0;i < H;i++){
			scanf("%s",str);
			for(int j = 0;j < W;j++){
				if(str[j] == '.'){
					data[i+1][j+1] = 0;
				}else if(str[j] == '#'){
					data[i+1][j+1] = 1;
				}else if(str[j] == '@'){
					data[i+1][j+1] = 2;
					sy = i+1;
					sx = j+1;
				}
			}
		}
		//show(data,W,H);

		ans = 1;
		count(data,sx,sy);

		printf("%d\n",ans);
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <ctime>
#include <iterator>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
    int nb_lignes,nb_colonnes;
    while(cin>>nb_colonnes>>nb_lignes)
    {
        if(nb_lignes == 0)
            break;
        int res = 1;
        vector<string> lab(nb_lignes);
        vector<vector<bool> > visites(nb_lignes,vector<bool>(nb_colonnes,false));
        for(int c=0;c<nb_lignes;c++) cin>>lab[c];
        int xdep,ydep=0;
        for(xdep=0;xdep<nb_lignes&&lab[xdep][ydep]!='@';xdep++){ for(ydep=0;ydep<nb_colonnes&&lab[xdep][ydep]!='@';ydep++);if(lab[xdep][ydep]=='@')break;}
        vector<pair<int,int> > parcours;
        visites[xdep][ydep]=true;
        parcours.push_back(make_pair(xdep,ydep));
        while(parcours.size())
        {
            int xact = parcours.back().first;
            int yact = parcours.back().second;
            parcours.pop_back();
            int dx[4]={1,-1,0,0};
            int dy[4]={0,0,1,-1};
            for(int c=0;c<4;c++)
            {
                int x2 = xact + dx[c];
                int y2 = yact + dy[c];
                if(x2>=0&&x2<nb_lignes&&y2>=0&&y2<nb_colonnes&&lab[x2][y2]!='#'&&!visites[x2][y2])
                {
                    visites[x2][y2]=true;
                    res++;
                    parcours.push_back(make_pair(x2,y2));
                }
            }
        }
        cout<<res<<endl;
    }
}