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 <bits/stdc++.h>
using namespace std;
bool mp[50][50];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int h,w;
int dfs(int y,int x){
  if(mp[y][x])return 0;
  int ret=1;
  mp[y][x]=1;
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
    ret+=dfs(ny,nx);
  }
  return ret;
}
  
int main(){
  string s;
  int si,sj;
  while(cin>>w>>h && w&&h){
    memset(mp,0,sizeof(mp));
    for(int i=0;i<h;i++){
      cin>>s;
      for(int j=0;j<w;j++){
        if(s[j]=='#') mp[i][j]=1;
        else if(s[j]=='@') {si=i;sj=j;}
      }
    }
    cout<<dfs(si,sj)<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  while (1){
    int W, H;
    cin >> W >> H;
    if (W == 0 && H == 0){
      break;
    }
    vector<vector<char>> c(H + 2, vector<char>(W + 2, '#'));
    for (int i = 1; i <= H; i++){
      for (int j = 1; j <= W; j++){
        cin >> c[i][j];
      }
    }
    int sy, sx;
    for (int i = 1; i <= H; i++){
      for (int j = 1; j <= W; j++){
        if (c[i][j] == '@'){
          sy = i;
          sx = j;
        }
      }
    }
    c[sy][sx] = '.';
    int ans = 0;
    vector<vector<bool>> used(H + 2, vector<bool>(W + 2, false));
    used[sy][sx] = true;
    queue<pair<int, int>> Q;
    Q.push(make_pair(sy, sx));
    while (!Q.empty()){
      int y = Q.front().first;
      int x = Q.front().second;
      Q.pop();
      ans++;
      for (int i = 0; i < 4; i++){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if (!used[y2][x2] && c[y2][x2] == '.'){
          used[y2][x2] = true;
          Q.push(make_pair(y2, x2));
        }
      }
    }
    cout << ans << endl;
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <string.h>
#include <queue>
#include <map>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	int w, h;
	char world[21][21];
	while(1)
	{
		scanf("%d %d", &w, &h);
		if (w == 0 && h == 0) break;
		int sx = -1, sy = -1;
		int memo[20][20];
		memset(memo, 0, 20 * 20 * sizeof(int));
		REP(i, h)
		{
			scanf("%s", world[i]);
			if (sx == -1)
			{
				REP(j, w)
					if (world[i][j] == '@')
					{
						sx = j;
						sy = i;
					}
			}
		}
		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(sx, sy));
		memo[sy][sx] = 1;
		int area = 0;
		while(!q.empty())
		{
			std::pair<int, int> p = q.front();
			q.pop();
			area++;
			int x = p.first;
			int y = p.second;
			// left
			if (x > 0 && world[y][x-1] == '.' && memo[y][x-1] == 0)
			{
				memo[y][x-1] = 1;
				q.push(make_pair(x-1, y));
			}
			if (x < (w-1) && world[y][x+1] == '.' && memo[y][x+1] == 0)
			{
				memo[y][x+1] = 1;
				q.push(make_pair(x+1, y));
			}
			// up
			if (y > 0 && world[y-1][x] == '.' && memo[y-1][x] == 0)
			{
				memo[y-1][x] = 1;
				q.push(make_pair(x, y-1));
			}
			if (y < (h-1) && world[y+1][x] == '.' && memo[y+1][x] == 0)
			{
				memo[y+1][x] = 1;
				q.push(make_pair(x, y+1));
			}
		}
		printf("%d\n", area);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int W,H,a,b,c;
int t[20][20];
char moji;
int ty[4] = {0,1,0,-1};
int tx[4] = {1,0,-1,0};

void syokika(){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++){
      t[i][j]=0;
    }
  }
  c=0;
}
void visit(int y,int x){
  c++;
  t[y][x]=1;
  int nx,ny;
  for(int i=0;i<4;i++){
    ny=y+ty[i];
    nx=x+tx[i];
    if(0<=ny&&ny<H&&0<=nx&&nx<W&&t[ny][nx]==0){
      visit(ny,nx);
    }
  }
}
int main(){
  while(true){
    syokika();
    cin>>W>>H;
    if(W==0&&H==0)break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>moji;
	if(moji=='.')t[i][j]=0;
	if(moji=='@'){
	  a=i;
	  b=j;
	}
	if(moji=='#')t[i][j]=-1;
      }
    }
    visit(a,b);
    cout<<c<<endl;
  }
  return 0; 
}

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

int standpanel;
char tile[31][31];

void check(int i,int j)
{
	if(tile[i][j]=='.')
	{
		tile[i][j]='#';
		standpanel++;
		check(i-1,j);
		check(i,j-1);
		check(i+1,j);
		check(i,j+1);
		
	}
	
}


int main(){
	int W,H;
	while(cin>> H >> W &&W&&H)
	{
		standpanel = 0;
		for(int i=0;i<=25;i++)for(int j=0;j<=25;j++)tile[i][j]='#';
		int manx,many;
		for(int i=1;i<=W;i++)for(int j=1;j<=H;j++)
		{
			cin >> tile[i][j];
			if(tile[i][j]=='@'){manx = i;many = j;tile[i][j]='.';}
			
		}
		check(manx,many);
		cout << standpanel << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
char map[114][514];
int h, w, ans;
void dfs(int i, int j) {
	ans++;
	map[i][j] = '#';
	if (map[i - 1][j] == '.')dfs(i - 1, j);
	if (map[i + 1][j] == '.')dfs(i + 1, j);
	if (map[i][j - 1] == '.')dfs(i, j - 1);
	if (map[i][j + 1] == '.')dfs(i, j + 1);
	return;
}
int main() {
	while (cin >> h >> w, h, w) {
		ans = 0;
		int x, y;
		for (int i = 0; i < 30; i++)for (int j = 0; j < 30; j++)map[i][j] = '#';
		for (int i = 1; i <= w; i++)for (int j = 1; j <= h; j++) {
			cin >> map[i][j];
			if (map[i][j] == '@') { x = i; y = j; }
		}
		dfs(x, y);
		cout << ans << endl;
	}
}