Note that there are some explanatory texts on larger screens.

plurals
  1. POUVA 10189: Minesweeper
    primarykey
    data
    text
    <p>Here's the link to the problem: <a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=13&amp;page=show_problem&amp;problem=1130" rel="nofollow">http://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;Itemid=8&amp;category=13&amp;page=show_problem&amp;problem=1130</a></p> <p>This is my code and it works perfectly; however, it gives wrong answer whenever I submit it. Does anybody know why?</p> <p>NOTE: I pad the matrix with 2 extra rows and columns so that when I'm checking the left of the first column or the bottom of the last row, I don't get an error.</p> <pre><code>//A minesweeper generator #include &lt;iostream&gt; #include &lt;sstream&gt; using namespace std; char arr[102][102]; //2D dynamic array used temporarily int main() { int n, m; //Rows and columns int count = 0, recordNum = 0; //Number of mines around the current dot while(true) { //Keep processing records until "0 0" is encountered cin &gt;&gt; n &gt;&gt; m; if(n == 0 &amp;&amp; m == 0 ) //End of input break; //Read the values into the array for(int i = 1; i &lt; n+1; i++) { //Rows for(int j = 1; j &lt; m+1; j++) { //Columns cin &gt;&gt; arr[i][j]; } } //Process the values of the array and generate the numbers for(int i = 1; i &lt; n+1; i++) { //Rows for(int j = 1; j &lt; m+1; j++) { //Columns if(arr[i][j] == '*') continue; else { //Count the number of mines around this dot if(arr[i-1][j-1] == '*') count++; if(arr[i-1][j] == '*') count++; if(arr[i-1][j+1] == '*') count++; if(arr[i][j-1] == '*') count++; if(arr[i][j+1] == '*') count++; if(arr[i+1][j-1] == '*') count++; if(arr[i+1][j] == '*') count++; if(arr[i+1][j+1] == '*') count++; } //Create a buffer to convert the count to a char stringstream buffer; buffer &lt;&lt; count; arr[i][j] = buffer.str().at(0); count = 0; //Finally reset the counter } } if(recordNum &gt; 0) cout &lt;&lt; endl; recordNum++; cout &lt;&lt; "Field #" &lt;&lt; recordNum &lt;&lt; ":\n"; //Output the values for(int i = 1; i &lt; n+1; i++) { //Rows for(int j = 1; j &lt; m+1; j++) { //Columns cout &lt;&lt; arr[i][j]; } cout &lt;&lt; endl; } } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload