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<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
 
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
 
using namespace std;
 
 int dx[4] = {1,0,-1,0};
 int dy[4] = {0,1,0,-1};

void dfs(vector<string> &map,vector<vector<bool> > &move,int x,int y,int h, int w){
  
    if(x < 0 || x >=w || y < 0 || y >=h){
      return ;
    }

    if(map[y][x] == '#'){
      return;
    }

    if(move[y][x]){
      return;
    }

    move[y][x] = true;

    for(int i=0;i<4;i++){
      dfs(map,move,x+dx[i],y+dy[i],h,w);
    }

    return;
}


int main()
{

  while(true){

    int w,h;
    cin >> w >> h;

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

    vector<string> map(h);    
    vector<vector<bool> > move(h,vector<bool>(w,false));
    int x=0,y=0;
    int count=0;

    for(int i=0;i<h;i++){
      cin >> map[i];
      //cout << map[i] << endl;
    }

    for(int i=0;i<w;i++){
      for(int k=0;k<h;k++){
        if(map[k][i]=='@'){
          x=i;
          y=k;
       
        //  cout << w << "," << h << endl;
        // cout << x << "," << y << endl; 
        }
        
     }
    
    }


    dfs(map,move,x,y,h,w);

   for(int i=0;i<w;i++){
    for(int k=0;k<h;k++){
      if(move[k][i]){
        count++;
      }
    }
   }
  
    cout << count << endl;

  }

    return 0;
}

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

using namespace std;

struct Coord {
  int row;
  int col;
};

int solve (int W, int H);
  
int main () {
  int W, H;

  while(W!=0 && H!=0)
    {
      scanf("%d%d", &W, &H);
      if(W!=0 && H!=0)
	{
          printf("%d\n", solve(W,H));
	}
    }
  return 0;
}

int solve (int W, int H) {
  int n=0;
  char M[H+2][W+2];
  Coord start;
  for (int i=0; i<=W+1; i++) { M[0][i] = '#'; M[H+1][i] = '#'; }
  for (int i=1; i<=H; i++) { M[i][0] = '#'; M[i][W+1] = '#'; } 
  for (int i=1; i<=H; i++) {
    for (int j=1; j<=W; j++) {
      scanf(" %c", &M[i][j]);
      if (M[i][j]=='@') {
	start.row = i;
	start.col = j;
      }
    }
  }

  
  stack<Coord> S;
  S.push(start);
  while (!S.empty()) {
    Coord current = S.top(); S.pop();
    n++;
    int D1[]={1,0,-1,0}; int D2[]={0,-1,0,1};
    for (int d=0; d<4; d++) {
      Coord nc = current;
      nc.row += D1[d];
      nc.col += D2[d];
      if(M[nc.row][nc.col]!='#' && M[nc.row][nc.col]!='*' && M[nc.row][nc.col]!='@')
	{
	  M[nc.row][nc.col] = '*';
	  S.push(nc);
	}
    } 
    
  }
  return n;
}

C++: #include <iostream>
#include <queue>
#include <utility>
#include <array>

using namespace std;

typedef pair<int, int> pii;

int height, width;
int sx, sy;
int ans = 0;
array<int, 4> dx = {0, 0, 1, -1};
array<int, 4> dy = {1, -1, 0, 0};


void bfs()
{
    queue<pii> p;
    p.push({sx, sy});
    
    while (!p.empty()) {
        pii q = p.front(); p.pop();
        
        //??????
        int cx = p.first;
        int cy = p.second;

        for (int i = 0; i < 4; ++i) {
            int nx = cx + dx.at(i);
            int ny = cy + dy.at(i);

            if (nx >= 0 && nx < width && ny >= 0 && ny < height 
                    && field.at(ny).at(nx) == '.') {

                ans++;
                p.push({nx, ny});
            }
        }
    }

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


int main()
{
    while (cin >> height >> width) {
        if (height == 0 && width == 0) break;

        ans = 0;
        
        vector<vector<char>> field(height, vector<char>(width));

        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                cin >> field.at(y).at(x);

                if (field.at(y).at(x) == '@') {
                    sx = x; sy = y;
                }
            }
        }

        bfs();
    }

    return 0;
}

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

char mas[111][111];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int sx,sy;
int w,h,cou;

int dfs(int x,int y);
int main(){
  while(1){
    cou=0;
    cin>>w>>h;
    if(w==0 && h==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>mas[i][j];
	if(mas[i][j]=='@'){
	  sx=j;
	  sy=i;
	}
      }
    }
    dfs(sx,sy);
    cout<<cou<<endl;
  }
}
int dfs(int x,int y){
  mas[y][x]='#';
  cou++;
  for(int i=0;i<4;i++){
    int nextx=x+dx[i];
    int nexty=y+dy[i];
    if(0<=nextx && nextx<w && 0<=nexty && nexty<h && mas[nexty][nextx]=='.'){
      dfs(nextx,nexty);
    }
  }
}

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

using namespace std;
typedef pair<int, int> pii;

#define W_MAX 20
#define H_MAX 20

#define B '.'
#define R '#'
#define M '@'

char map[W_MAX][H_MAX];

int main(){

  while(true){
    int W,H;
    cin >> W >> H;

    if(W==0 && H==0) break;

    pii s; //start

    for(int i=0; i<H; i++){
      getchar();
      for(int j=0; j<W; j++){
	scanf("%c", &map[i][j]);
	if(map[i][j]==M){
	  s = make_pair(i,j);
	  map[i][j] = R;
	}
      }
    }

    stack<pii> st;
    st.push(s);
    int dx[] = {-1,0,0,1}; int dy[] = {0,1,-1,0};
    int ans=0;
    while(!st.empty()){
      pii p = st.top(); st.pop();
      int x = p.first; int y = p.second;
      ans++;
      for(int i=0; i<4; i++){
	int nx = x+dx[i]; int ny = y+dy[i];
	if(nx>=0 && nx<H &&
	   ny>=0 && ny<W &&
	   map[nx][ny]==B){
	  st.push(make_pair(nx,ny));
	  map[nx][ny] = R;
	}
      }
    }

    cout << ans << endl;

  }
}