Page 26 of 28

Re: 10189 - Minesweeper

Posted: Tue Aug 12, 2014 12:03 pm
by Shahidul.CSE

Code: Select all

Rempved after accepted! :D 

Re: 10189 - Minesweeper

Posted: Wed Aug 13, 2014 12:24 am
by brianfry713
Always print a newline char at the end of the last line.

Post your full updated code if you still need help.

Re: 10189 - Minesweeper

Posted: Thu Aug 14, 2014 1:50 pm
by Shahidul.CSE
Removed after got Accepted !!

Re: 10189 - Minesweeper

Posted: Fri Aug 15, 2014 12:04 am
by brianfry713
The first code is correct as far as newlines go.

On line 25 instead of:
if(j != m) {
change it to something like:
if(j != m - 1) {

Apply similar changes to other lines in your code.

Re: 10189 - Minesweeper

Posted: Thu Sep 04, 2014 10:18 am
by fresher96
thanks very much guys !
i'm new for in the ACM problems
in the real contest is it the same that they give wrong answer for a single stupid blank line at the end !!!
or it's just here because of the online judge ?

Re: 10189 - Minesweeper

Posted: Thu Sep 04, 2014 6:59 pm
by brianfry713
Read the rules of the contest you are entering.

Re: 10189 - Minesweeper

Posted: Sat Sep 27, 2014 10:10 pm
by Ishtiaq11
>>>>>>>>>>Why Time Limit ? :cry: Please help.


#include<cstdio>
#include<iostream>
using namespace std;

int main()
{

int row,col,cnt = 0;
while(true)
{
cin >> row >> col ;
if(row == 0 && col == 0) break;
cnt++;
if(cnt > 1) cout << "\n";
int field[102][102] = {0};

for(int i = 0; i < row; i++){
for(int j =0; j < col; j++){
char temp;
cin >> temp;
if(temp == '*'){
field[j] = -1;

if(field[i-1][j-1] != -1) field[i-1][j-1]++;//lower row
if(field[i-1][j] != -1) field[i-1][j]++;//lower row
if(field[i-1][j+1] != -1) field[i-1][j+1]++;//lower row

if(field[j-1] != -1) field[j-1]++;//that row
if(field[j+1] != -1) field[j+1]++;//that row

if(field[i+1][j-1] != -1) field[i+1][j-1]++;//upper row
if(field[i+1][j] != -1) field[i+1][j]++;//upper row
if(field[i+1][j+1] != -1) field[i+1][j+1]++;//upper row
}
}
}

cout << "Field #" << cnt << ":\n" ;
for(int i = 0; i < row; i++){
for(int j =0; j < col; j++){
if(field[j] == -1) cout << '*' ;
else cout << field[j];
}
cout << "\n" ;
}
}

return 0;
}

Re: 10189 - Minesweeper

Posted: Mon Sep 29, 2014 8:18 pm
by brianfry713
If i or j equals 0 then you shouldn't read or write to field[j - 1].

Re: 10189 - Minesweeper

Posted: Sun Nov 09, 2014 6:56 pm
by mohdali231993

Code: Select all

#include <iostream>
using namespace std;
int main()
{
 int a,b,i,j,count=0;int arr[101][101];char carr[101][101];
 while(1)
 {cin>>a>>b;
  
  if(!a && !b)
   break;
  count++;if(count>1){cout<<endl;}
  for(i=1;i<=a;i++)
  {
   for(j=1;j<=b;j++)
   {
    char c;
    cin>>c;
    carr[i][j]=c;
    if(c==42)
    {
     arr[i-1][j-1]++;
     arr[i][j-1]++;
     arr[i+1][j-1]++;
     arr[i-1][j]++;
     arr[i+1][j]++;
     arr[i-1][j+1]++;
     arr[i][j+1]++;
     arr[i+1][j+1]++;
    }

   }

  }
  cout<<"Field #"<<count<<":"<<endl;
  for(i=1;i<=a;i++)
  {
   for(j=1;j<=b;j++)
   {
    if(carr[i][j]==42)
    cout<<"*";
    else
    cout<<arr[i][j];
   }
  
   cout<<endl;
  }
  
  for(i=0;i<=a+1;i++)
  for(j=0;j<=b+1;j++)
  {arr[i][j]=0;carr[i][j]='.';}

 }

 return 0;
}
Guys help!!!
cannot get around the wa

Re: 10189 - Minesweeper

Posted: Sun Nov 09, 2014 8:11 pm
by lighted
Use code tags. Increase array limits to

Code: Select all

int arr[110][110];
char carr[110][110];
Don't forget to remove your code after getting accepted. 8)

Re: 10189 - Minesweeper

Posted: Sun Nov 09, 2014 8:58 pm
by mohdali231993
Thanks man :D
But why exactly 110??

Re: 10189 - Minesweeper

Posted: Mon Nov 10, 2014 3:39 pm
by lighted
If you make your array arr global or add memset(arr, 0, sizeof(arr)) before each query, it is enough to increase to arr[102][102].

I hope you'll understand why it is exactly 102 yourself. :)

Re: 10189 - Minesweeper

Posted: Wed Dec 03, 2014 3:03 pm
by ehsanulbigboss
Thanks to lighted

Re: 10189 - Minesweeper

Posted: Wed Dec 03, 2014 6:53 pm
by lighted
You don't clear all previous values. Increase it with +1. Because you access to that values when printing results. Or use memset of whole array. :)

Code: Select all

for (i = 0 ; i <= row + 1; i++)
    for (j = 0 ; j <= column + 1; j++)
        array[i][j] = 0;

Re: 10189 - Minesweeper

Posted: Fri Dec 05, 2014 3:30 am
by Echoless
Thanks again to lighted.:)