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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

void dfs(int x,int y);
int w,h;
 
int count;
bool flag;
char maze[21][21];
bool reached[501][501];
 
int main(){
        int w,h;

    while(cin>>w>>h){

            if(w==0&&h==0){
                break;
            }

            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    cin>>maze[i][j];
                }
            }


// cout<<endl;
//              for(int i=0;i<h;i++){
//                 for(int j=0;j<w;j++){
//                     cout<<maze[i][j];
//                 }
//                 cout<<endl;
//             }

//             cout<<endl;


// cout<<endl;
//             for(int i=0;i<21;i++){
//                 for(int j=0;j<21;j++){
//                     cout<<maze[i][j];
//                 }
//                 cout<<endl;
//             }cout<<endl;

            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(maze[i][j]=='@'){
                        dfs(j,i);
                    }
                }
            }

            // for(int i=0;i<h;i++){
            //     for(int j=0;j<w;j++){
            //         cout<<maze[i][j];
            //     }
            //     cout<<endl;
            // }

            count=0;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(maze[i][j]=='!')count++;
                }
            }

            cout<<count<<endl;

            for(int i=0;i<22;i++){
                for(int j=0;j<22;j++){
                    maze[i][j]='%';
                }
            }

            // cout<<endl;


        }
    


 
    return 0;
}
 
 
void dfs(int x,int y){
    maze[y][x]='!';

    for(int i=0;i<4;i++){
        int mx=x+dx[i];
        int my=y+dy[i];
        if(maze[my][mx]=='.'){
            dfs(mx,my);
        }
        if(mx<0||w<=mx||my<0||h<=my){
            continue;
        }//??????????????´?????´???->???????????????



        
    } 
}

C++: #include<iostream>
#include<string>
using namespace std;
int w,h;
string map[40];
int vec[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
int move(int x,int y){
	int ans=0;
	map[x][y]='#';
	for(int i=0;i<4;i++){
		if((x+vec[i][0]>=0)&&(y+vec[i][1]>=0)&&(x+vec[i][0]<h)&&(y+vec[i][1]<w)){
			if(map[x+vec[i][0]][y+vec[i][1]]=='.'){
				ans+=move(x+vec[i][0],y+vec[i][1]);
			}
		}
	}
	return ans;
}

int main(){
	while(cin>>w>>h,w){
		int fx,fy;
		for(int i=0;i<h;i++){
			cin>>map[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]=='@'){
					fx=i;
					fy=j;
					break;
				}
			}
		}
		int ans=move(fx,fy);
		cout<<ans<<endl;
		
	}
}

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

int main(){

    int c[21][21],w,h;
    memset(c,0,sizeof(c));
    char t;
    while(1){
    cin>>w>>h;if(w==0&&h==0)return 0;
    for(int i=0;i<w*h;i++){cin>>t;c[i%w][i/w]=t;}
    for(int i=0;i<w*h;i++){
      for(int j=0;j<w*h;j++)
        if(c[j%w][j/w]==64){
	  if(c[j%w-1][j/w]==46)c[j%w-1][j/w]=64;
          if(c[j%w+1][j/w]==46)c[j%w+1][j/w]=64;
          if(c[j%w][j/w-1]==46)c[j%w][j/w-1]=64;
          if(c[j%w][j/w+1]==46)c[j%w][j/w+1]=64;
        }
    }
    int cou=0;
    for(int i=0;i<w*h;i++)if(c[i%w][i/w]==64)cou++;
    cout<<cou<<endl;
    } 
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;

void merge (int *first1, int *last1, int *first2, int *last2){
    int size1 = last1 - first1;
    int size2 = last2 - first2;
    int *result = new int[size1+size2];
    int i = 0;
    int j = 0;
    int index = 0;
    while (true){
        if (i < size1 && (first1[i] <= first2[j] || j >= size2)){
            result[index] = first1[i];
            ++i; ++index;
        }
        if (j < size2 && (first1[i] > first2[j] || i >= size1)){
            result[index] = first2[j];
            ++j; ++index;
        }
        if (i==size1 && j==size2){
            for (i=0; i<size1; ++i) first1[i] = result[i];
            for (j=0; j<size2; ++j) first2[j] = result[j+size1];
            delete[] result;
            return;
        }
    }
}
void MergeSort (int *first, int *last){
    int size = last - first;
    if(size <= 1) return;
    MergeSort(first, first+size/2);
    MergeSort(first+size/2, last);
    merge(first, first+size/2, first+size/2, last);
}


int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

int dx[3]={-1, 0, 1};
int dy[3]={-1, 0, 1};
int W, H;
char masu[20][20];
int cnt;

int dfs(int a, int b){
  masu[a][b] = '#';
  cnt++;
  REP(i, 3)REP(j, 3) if(masu[a+dx[i]][b+dy[j]]=='.' && abs(dx[i]+dy[j])==1) dfs(a+dx[i], b+dy[j]);
  return cnt;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    REP(j, H)REP(i, W) cin >> masu[i][j];

    int i0, j0;
    REP(j, H)REP(i, W) if(masu[i][j] == '@'){
      i0=i;
      j0=j;
      break;
    }

    cnt = 0;
    cnt = dfs(i0, j0);
    cout << cnt << endl;
  }
    return 0;
}