Language: C++


#Include <iostream>
#include <queue>

using namespace std;
static const int MV = 100;
typedef pair<int, int> T;

int main() {
  while(1) {
    int w, h, Gcount=0, sum=0;
    cin >> w >> h;
    if (w ==0 && h == 0) break;
    char M[h][w];
    int A[h][w];
    queue<T> Q;
    
    for (int i=0;i<h;i++) {
      for (int j=0;j<w;j++) {
	cin >> M[i][j];
	A[i][j]=MV;
	if (M[i][j] == '*')
	  Gcount++;
	if (M[i][j] == 'o'){
	  Q.push(make_pair(i, j));
	  A[i][j]=0;
	}
      }
    }
    /*
      for (int i=0;i<h;i++) {
      for (int j=0;j<w;j++) {
      cout << A[i][j];
      }cout << endl;
      }
    */
    while(Gcount != 0 || Q.empty()) {
      if(Q.empty()) break;//cout << -1<< endl;
      int Dy[4]={1, 0, -1, 0}, Dx[4]={0, 1, 0, -1}, ny, nx;
      M[Q.front().first][Q.front().second]='+';
      for (int i=0;i<4;i++) {
	ny = Q.front().first + Dy[i]; nx = Q.front().second + Dx[i];
	//      cout << endl << ny << "    " << nx << endl;
	if (M[ny][nx] == '.' && 0<=nx && nx<w && 0<=ny && ny<h) {
	  Q.push(make_pair(ny, nx));
	  //	cout << endl << "         " << ny << "   " << nx << endl;
	  M[ny][nx]='+';
	  A[ny][nx]=A[Q.front().first][Q.front().second] + 1;
	}
	if (M[ny][nx] == '*' && 0<=nx && nx<w && 0<=ny && ny<h) {
	  Gcount--;
	  M[ny][nx]='+';
	  sum+=A[Q.front().first][Q.front().second] + 1;
	  //	cout << endl << sum << endl;
	  for (int j=0;j<h;j++) {
	    for (int k=0;k<w;k++) {
	      A[j][k]=MV;
	      if (M[j][k] == '+') {
		M[j][k] = '.';
	      }
	    }
	  }
	  int q=Q.size();
	  for (int j=1;j<q;j++) {
	    //while(!Q.empty()) {
	    Q.pop();
	  }
	  Q.push(make_pair(ny, nx));
	  A[ny][nx] = 0;
	  i=4;
	}
      }
      /*    
	    for (int i=0;i<h;i++) {
	    for (int j=0;j<w;j++) {
	    cout << A[i][j] << "      ";
	    }cout << endl;
	    }
	    cout << endl;
      */
      
      Q.pop();
    }
    if(sum == 0) cout << -1 << endl;
    else cout << sum << endl;
  }
}

  /*
  while(!Q.empty() || a) {
    for(int i=0; i<4; i++) {
      int nx = Q.front().first + dx[i], ny = Q.front().second + dy[i];
      if(A[nx][ny]!='x' && 0<=nx && nx<w && 0<=ny && ny<h) {
	Q.push(make_pair(nx, ny));
	A[nx][ny]='+';
	A[nx][ny]=AA[Q.front().first][Q.front().second]+1;
	for (int aa=0;aa<h;aa++){
	  for (int bb=0;bb<w;bb++){
	    cout << AA[aa][bb];
	  }cout << endl;
	}
	}

      if(A[nx][ny]=='*') {
      	a=false;
      }
    }
    Q.pop();
  }
  */

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #Include; did you mean #include?
    2 | #Include <iostream>
      |  ^~~~~~~
      |  include
a.cc: In function 'int main()':
a.cc:12:5: error: 'cin' was not declared in this scope
   12 |     cin >> w >> h;
      |     ^~~
a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    3 | #include <queue>
  +++ |+#include <iostream>
    4 | 
a.cc:84:18: error: 'cout' was not declared in this scope
   84 |     if(sum == 0) cout << -1 << endl;
      |                  ^~~~
a.cc:84:18: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:84:32: error: 'endl' was not declared in this scope
   84 |     if(sum == 0) cout << -1 << endl;
      |                                ^~~~
a.cc:4:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    3 | #include <queue>
  +++ |+#include <ostream>
    4 | 
a.cc:85:10: error: 'cout' was not declared in this scope
   85 |     else cout << sum << endl;
      |          ^~~~
a.cc:85:10: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:85:25: error: 'endl' was not declared in this scope
   85 |     else cout << sum << endl;
      |                         ^~~~
a.cc:85:25: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'