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 <cstring>
#include <functional>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

const int vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0};

int W, H;
std::string s[21];
bool is_searched[21][21];

int dfs(int x, int y) {
	int ret = 0;
	is_searched[x][y] = true;

	for(int i = 0; i < 4; ++i) {
		int nx = x + vx[i], ny = y + vy[i];

		if(0 <= nx && nx < H && 0 <= ny && ny < W &&
		   !is_searched[nx][ny] && s[nx][ny] == '.') {

			ret += dfs(nx, ny) + 1;
		}
	}

	return ret;
}

int solve() {
	int ret = 0;
	int sx, sy;

	std::memset(is_searched, false, sizeof is_searched);

	for(int i = 0; i < H; ++i) {
		for(int j = 0; j < W; ++j) {
			if(s[i][j] == '@') {
				sx = i, sy = j;
				break;
			}
		}
	}

	ret = dfs(sx, sy) + 1; // +1 は'@' の分

	return ret;
}

int main() {

	while(cin >> W >> H, W | H) {
		for(int i = 0; i < H; ++i) {
			cin >> s[i];
		}

		int ans = solve();

		cout << ans << endl;
	}

	return 0;
}

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

int w, h, ans;
int d[4][2] = { { 1, 0 }, { -1, 0 }, {0, 1}, {0, -1} };
char map[20][20];

void search_dfs(int x, int y){
	if( x < 0 || x >= w || y < 0 || y >= h ) return;
	if( map[y][x] != '.' ) return;
	ans ++;
	map[y][x] = '*';
	for(int i = 0; i < 4; i++)
		search_dfs( x + d[i][0], y + d[i][1] );
}

int main(void){

	while( 1 ) {
		cin >> w >> h;
		if( w == 0 && h == 0 ) break;
		ans = 0;

		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] == '@' ) {
					map[i][j] = '.';
					search_dfs(j, i);
				}

		cout << ans << endl;
	}

	return 0;
}

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

int w, h;
char tiles[20][21];

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

bool isRegion(int x, int y){
    return x >= 0 && x < w && y >= 0 && y < h;
}

int main(){
    while(1){
        cin >> w >> h;
        if(!w && !h) break;
        
        int sx, sy;
        for(int i = 0; i < h; i++){
            cin >> tiles[i];
            
            auto j = find(tiles[i], tiles[i]+w, '@');
            if(j != tiles[i] + w){
                sx = j - tiles[i]; sy = i;
            }
        }
        
        int cnt = 0;
        queue<pair<int, int> > q;
        q.push(make_pair(sx, sy));
        while(!q.empty()){
            cnt++;
            int x = q.front().first, y = q.front().second;
            q.pop();
            
            for(int i = 0; i < 4; i++){
                int nx = x + dx[i], ny = y + dy[i];
                
                if(isRegion(nx, ny) && tiles[ny][nx] == '.'){
                    tiles[ny][nx] = '#';
                    q.push(make_pair(nx, ny));
                }
            }
        }
        cout << cnt << endl;
        
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

void dfs( int W, int H, int w_index, int h_index, vector< vector<char> > &V, int &ans );

int main(int argc, char const *argv[]) {
    vector< vector<char> > vec;

    int w, h, w_index, h_index;
    int ans = 1;
    vector<int> sums;

    while (1) {
        cin >> w >> h;

        if( w==0 || h==0 ) break;

        vec.resize(h);
        for (int i = 0; i < h; i++) {
            vec[i].resize(w);
        }

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

        for (auto it = vec.begin(); it != vec.end(); it++ ) {
            auto iter = find(it->begin(), it->end(), '@');

            if(iter!=it->end()){
                h_index = distance( vec.begin(), it );
                w_index = distance( it->begin(), iter );
            }
        }

        dfs( w, h, w_index, h_index, vec, ans );

        std::cout << ans << std::endl;
    }

    for( auto it = sums.begin(); it != sums.end(); it ++ ){
        cout << *it << endl;
    }

    return 0;
}

void dfs( int W, int H, int w_index, int h_index, vector< vector<char> > &V , int &ans ){
    int dx[4] = { 1, 0, -1, 0 };
    int dy[4] = { 0, 1, 0, -1 };
    V[h_index][w_index] = '#';

    for( int i = 0; i < 4; i++ ){
        int nx = w_index + dx[i];
        int ny = h_index + dy[i];

        if( 0 <= nx && nx < W && 0 <= ny && ny < H && V[ny][nx] != '#' ){
            ans++;
            dfs( W, H, nx, ny, V, ans );
        }
    }

    return;
}

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

char s[32][32];
int cnt;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

void dfs(int y, int x)
{
	cnt++;
	s[y][x]=0;
	for(int i=0; i<4; i++)
	{
		int ny=y+dy[i];
		int nx=x+dx[i];
		if(s[ny][nx]=='.')
			dfs(ny,nx);
	}
}

int main()
{
	int w,h;
	while(cin >> w >> h, w||h)
	{
		cnt = 0;
		memset(s,0,sizeof(s));
		for(int i=1; i<=h; i++)
		{
			cin >> s[i]+1;
		}

		for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
		if(s[i][j]=='@')
		{
			dfs(i,j);
			break;
		}
		cout << cnt << endl;
	}
}

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

int w, h, m;
string s[20];

void dfs(int i, int j) {
	s[i][j] = '#';
	m++;

	if (i > 0 && s[i - 1][j] == '.')
		dfs(i - 1, j);
	if (i < h - 1 && s[i + 1][j] == '.')
		dfs(i + 1, j);

	if (j > 0 && s[i][j - 1] == '.')
		dfs(i, j - 1);

	if (j < w - 1 && s[i][j + 1] == '.')
		dfs(i, j + 1);
}

int main()
{
	cin >> w >> h;

	while (w > 0 && h > 0) {
		m = 0;

		for (int i = 0; i < h; i++)
			cin >> s[i];

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

		cout << m << endl;
		cin >> w >> h;
	}
}