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>
#include<cstdio>
using namespace std;

char maps[22][22];
int count;
int me[2];
int w,h;

void init(){
  for(int i = 0; i < 22; i++){
    for(int j = 0; j < 22; j++){
      maps[i][j] = '#';
    }
  }
}

void where(int w,int h){
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(maps[i][j] == '@'){
	me[0] = i;
	me[1] = j;
	maps[i][j] = '.';
	return;
      }
    }
  }
}

void search(int y, int x){
  maps[y][x] = '#';
  count++;
  if(maps[y - 1][x] == '.' && y > 0){
    search(y - 1, x);
  }
  if(maps[y + 1][x] == '.' && y < h){
    search(y + 1, x);
  }
  if(maps[y][x - 1] == '.' && x > 0){
    search(y, x - 1);
  }
  if(maps[y][x + 1] == '.' && x < w){
    search(y, x + 1);
  }
  return;
}
  
int main(){
  while(true){
    // input 
    cin >> w >> h;
    if(!w && !h){
      break;
    }
    init();
    for(int i = 0; i < h; i++){
      cin >> maps[i];
    }
    count = 0;
    where(w, h);
    search(me[0], me[1]);

    cout << count << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<queue>
#include<map>
using namespace std;
int main(){
	int w,h;
	while(cin>>w>>h,w+h!=0){
		string ban[100];
		int sx=0,sy=0;
		queue< pair<int,int> >bfs;
		bool table[100][100];
		for(int i=0;i<100;i++)for(int j=0;j<100;j++)table[i][j]=false;
		
		for(int i=0;i<h;i++){
			cin>>ban[i];
			for(int j=0;j<ban[i].size();j++){
			if(ban[i][j]=='@')sy=i,sx=j;
			}
		}
		pair<int,int> s(sx,sy);
		bfs.push(s);
		table[sy][sx]=true;
		int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
		while(bfs.empty()==false){
			pair<int,int>now=bfs.front();
			bfs.pop();
			int nx=now.first,ny=now.second;
			for(int i=0;i<4;i++){
				if(nx+dx[i]>=0&&nx+dx[i]<w&&ny+dy[i]>=0&&ny+dy[i]<h){
					if(table[ny+dy[i]][nx+dx[i]]==false&&ban[ny+dy[i]][nx+dx[i]]=='.'){
					pair<int,int>tmp(nx+dx[i],ny+dy[i]);
					bfs.push(tmp);
					table[tmp.second][tmp.first]=true;
				}
				}
			}
		}
		int cnt=0;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(table[i][j])cnt++;
		cout<<cnt<<endl;
		for(int i=0;i<100;i++)ban[i].clear();
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>

using namespace std;

int w,h;
int ans=1;
char tile[21][21];

void saiki(int x,int y){
	if(x<0 | x>w | y<0 | y>h)return;
	tile[x][y]='#';
	if(tile[x-1][y]=='.')ans++,saiki(x-1,y);
	if(tile[x+1][y]=='.')ans++,saiki(x+1,y);
	if(tile[x][y-1]=='.')ans++,saiki(x,y-1);
	if(tile[x][y+1]=='.')ans++,saiki(x,y+1);
}

int main(void){
	int a,b; 
	while(1){
		scanf("%d %d",&w,&h);
		if(w==0 && h==0)break;
		ans=1;
		for(a=0;a<h;a++){
			scanf("%s",tile[a]);
		}
		for(a=0;a<h;a++){
			for(b=0;b<w;b++){
				if(tile[a][b]=='@')saiki(a,b);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
char m[22][22];
int main() {
	int w, h;
	pii pos;
	while (cin>>w>>h,w) {
		fill((char*)m, (char*)m + 22 * 22,'#');
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cin >> m[i][j];
				if (m[i][j] == '@')pos = pii(i, j);
			}
		}
		int sum = 1;
		queue<pair<int, int>> que;
		que.push(pos);
		while (!que.empty()) {
			int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
			for (int i = 0; i < 4; i++) {
				int x = que.front().second+dx[i], y = que.front().first+dy[i];
				if (m[y][x] == '.') {
					m[y][x] = '@';
					sum++;
					que.push(pii(y, x));
				}
			}
			que.pop();
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

struct Point{
	int x,y;
};

const Point DIR[4] = {{1,0},{0,1},{-1,0},{0,-1}};

class Searcher{
private:
	int w,h;
	char map[20][20];
	Point init;
	
	int cnt;
	bool visited[20][20];
	
public:
	//面倒なので、中で実装する
	Searcher(int w,int h, char map[20][20],Point init){
		this->w = w;
		this->h = h;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				this->map[i][j] = map[i][j];
				visited[i][j] = false;
			}
		}
		this->init = init;
		cnt = 0;
	}
	
	int solve(){
		dfs(init);
		return cnt;
	}
	
private:
	bool inField(Point pos){
		return 0<= pos.x && pos.x < w && 0<= pos.y && pos.y < h;
	}

	void dfs(Point pos){
		cnt++;
		visited[pos.y][pos.x] = true;
		for(int i=0;i<4;i++){
			Point next = {pos.x + DIR[i].x, pos.y + DIR[i].y};
			if(inField(next)==true){
				if(visited[next.y][next.x] == false && map[next.y][next.x] == '.'){
					dfs(next);
				}
			}
		}
	}
};

int main(){
	while(true){
		int w,h;
		cin >> w >> h;
		if(w==0){
			break;
		}
		char map[20][20];
		Point init;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cin >> map[i][j];
				if(map[i][j]=='@'){
					init = (Point){j,i};
					map[i][j] = '.';
				}
			}
		}
		Searcher searcher(w,h,map,init);
		int result = searcher.solve();
		cout << result << endl;
	}
	return 0;
}