I got a problem solving this.
I tried to use the sample input and I got exactly the same output as the sample output but I still got WA. Even my output had the same format and same number of characters including every new line but still got "wrong answer".
I don't have any idea.
Any suggestion?
This is my code:
#include<iostream>
#include<fstream>
using namespace std;
int main(){
long cols = 0, rows = 0;
long nThField = 0;
long mines = 0;
long checkedRow = 0;
long checkedCol = 0;
while (cin>>rows>>cols){// get # of row n col
char field[rows][cols];
if (!rows && !cols) break;
else if (nThField > 0) cout<<"\n";
for (int i = 0; i < rows; i++){// iterate row
for (int j = 0; j < cols; j++){// iterate col
cin>>field[i][j];
}
}
//output the value
nThField++;
cout<<"Field #"<<nThField<<":"<<"\n";
for (int i = 0; i < rows; i++){// iterate row
for (int j = 0; j < cols; j++){// iterate col
if (field[i][j] == '.'){//print the number of mine around
// checking for possible mine around in 3x3 area
mines = 0;
for (int tRow = -1; tRow <= 1; tRow++){
for (int tCol = -1; tCol <= 1; tCol++){
checkedRow = i + tRow;
checkedCol = j + tCol;
if (checkedRow < 0 || checkedCol < 0) continue;// if col or row out of bound
if (field[i + tRow][j + tCol] == '*'){
mines++;
}
}
}
cout<<mines;
} //end of printing the number of mine
else cout<<'*'; //print the mine
}// end iterating col
cout<<"\n";
}// end iterating row
}
return 0;
}
Any help would be very appreciated