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<cmath>
#include<cstdio>
using namespace std;
int check(int j){
	if (j==2 || j==4 ||j==3)
	return j;
	else
	return 3;
}
int main(){
	int board[22][22];
	int w,h;
	char t;
	while(1){
		cin >>w >>h;
		for(int i=0;i<=21;i++){
			for(int j = 0;j<=21;j++){
				board[j][i]=4;
			}
		}//initialization
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> t ;
				if(t == '.')board[j][i] = 1;
				else if(t=='#')board[j][i]=2;
				else board[j][i] = 3;
			}
		}// input end
		int cmem = 2000;
		int c  = 0;
		while(cmem-c !=0){
				cmem = c;
			for(int i=1;i<=h;i++){
				for (int j= 1;j<=w;j++){
					if(board[j][i] ==3){
					board[j-1][i] =check(board[j-1][i]);
					board[j+1][i] =check(board[j+1][i]);
					board[j][i-1] =check(board[j][i-1]);
					board[j][i+1] =check(board[j][i+1]);
					}
				}
			}
			c = 0;
			for(int i=1;i<=h;i++){
				for (int j= 1;j<=w;j++){
					if (board[j][i] ==3) c+=1;
				}
			}
	
		}	
	
		cout <<c << endl;	
	}//while loop end
	return 0;
}

C++: 
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
#include<type_traits>
using namespace std;
char D[28][28];
int Y ;
void serch(int X, int Q) {
	if (D[X][Q] == '.'||D[X][Q]=='@') {
		Y++;
		D[X][Q] = '#';
		serch(X - 1, Q);
		serch(X + 1, Q);
		serch(X , Q-1);
		serch(X , Q+1);
		

	}
	else return;
}


int main() {
	int H, W;
	cin >> W >> H;
	for (int i = 0; i <28; i++) {
		for (int j = 0; j <28; j++) {
			D[i][j] = '#';
		}
	}
	int Sx,Sy;
	while (H) {
		 Y = 0;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				cin >> D[j][i];
				if (D[j][i] == '@') {
					Sx = j;
					Sy = i;
				}
			}
		}
		serch(Sx, Sy);
		
		cout << Y << endl;
		for (int i = 0; i <28; i++) {
			for (int j = 0; j <28; j++) {
				D[i][j] = '#';
			}
		}
		cin >> W >> H;
	}
	return 0;
}

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

int cnt, a[23][23];  //black : 0, red : 1

void dfs(int x, int y){
    cnt++;
    a[x][y] = 1;
    if(!a[x + 1][y]) dfs(x + 1, y);
    if(!a[x - 1][y]) dfs(x - 1, y);
    if(!a[x][y + 1]) dfs(x, y + 1);
    if(!a[x][y - 1]) dfs(x, y - 1);
    return;
}

int main(){
    while(1){
        int i, j, w, h, si, sj;
        char in;
        cin >> w >> h;
        if(w == 0)break;
        
        cnt = 0;
        for(i = 0; i <= h + 1; i++){
            a[i][0] = a[i][w + 1] = 1;
        }
        for(j = 0; j <= w + 1; j++){
            a[0][j] = a[h + 1][j] = 1;
        }
       
        i = 1;
        j = 1;
        while(i <= h){
            while(j <= w){
                cin >> in;
                //cout << "~~" << endl;
                if(in == '.'){
                   a[i][j] = 0;
                   j++; 
                }else if(in == '#'){
                    a[i][j] = 1;
                    j++;
                }else if(in == '@'){
                    si = i;
                    sj = j;
                    a[i][j] = 1;
                    j++;
                }
                //cout << j << endl;
            
            
            
            }
            i++;
            j = 1;
        }
        dfs(si, sj);
        cout << cnt << endl;
    }
    return 0;
}

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

string room[20];

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int dfs(int x, int y){
    int cnt = 1;
    for(int i = 0; i < 4; i++){
        int nx = x + dx[i], ny = y + dy[i];
        
        if(room[ny][nx] == '.'){
            room[ny][nx] = '#';
            cnt += dfs(nx, ny);
        }
    }
    return cnt;
}

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int w,h; cin >> w >> h;
        if(!w && !h) break;
        
        int sx, sy;
        for(int i = 0; i < h; i++){
            cin >> room[i];
            if(room[i].find('@') != -1){
                sx = room[i].find('@');
                sy = i;
            }
        }
        
        cout << dfs(sx, sy) << endl;
        
    }
}

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

using namespace std;


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

int w,h;
int map[21][21];

int count;
int init_x,init_y;

void dfs(int x,int y) {
  
  //cout << x << " " << y << endl;

  if(x<0 || x>=w || y<0 || y>=h) return;

  //if(map[x][y]==2) map[x][y]=0;

  if(map[x][y]>0) return;

  map[x][y]=3;

  count++;

  for(int i=0;i<4;i++) dfs(x+dx[i],y+dy[i]);

}

int main() {

  string buf;

  while(cin >> w >> h) {

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

    getline(cin,buf);

    for(int i=0;i<h;i++) {

      getline(cin,buf);

      for(int j=0;j<w;j++) {

	switch(buf[j]) {

	case '.':
	  map[j][i]=0;
	  break;

	case '#':
	  map[j][i]=1;
	  break;

	case '@':
	  map[j][i]=0;
	  init_x=j;
	  init_y=i;
	  break;

	}

      }

    }
    /*
    for(int i=0;i<h;i++) {

      for(int j=0;j<w;j++) {

	cout << map[j][i];

      }

      cout << endl;

    }
    
    cout << endl;

    cout << map[5][7] << endl;
    */
    count=0;

    dfs(init_x,init_y);
    /*
    cout << init_x << " " << init_y << endl;
    
    for(int i=0;i<h;i++) {

      for(int j=0;j<w;j++) {

	cout << map[j][i];

      }

      cout << endl;

    }
    */
    cout << count << endl;

  }

  return 0;

}

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

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

int w,h,res;
char field[20][20];

void dfs(int x,int y){
	res++;
	field[x][y] = '#';
	for(int i = 0;i < 4;i++){
		int nx = x + dx[i],ny = y + dy[i];
		if(nx >= 0 && nx < h && ny >= 0 && ny < w && field[nx][ny] == '.'){
			dfs(nx,ny);
		}
	}
}

int main(){
	int x,y;
	while(cin >> w >> h,w){
		res = 0;
		getchar();
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++) {
				field[i][j] = getchar();
				if(field[i][j] == '@'){
					x = i;
					y = j;
				}
			}
			getchar();
		}
		dfs(x,y);
		cout << res << endl;
	}
	return 0;
}