Page 7 of 7

Re: 10279 - Mine Sweeper

Posted: Tue Aug 12, 2014 8:57 pm
by Shahidul.CSE
Removed after accepted ! :D

Re: 10279 - Mine Sweeper

Posted: Fri Aug 15, 2014 12:08 am
by brianfry713
Shahidul.CSE wrote:Here I checked in[i+1].ch[j+1] and in[i-1].ch[j-1], even when they does not exist.(i.e. i or j equal to 0, n; Is this a mistake? But I checked all the test cases, I am getting correct output. For this checking program should get RE, not WA. Am I right?

So, is there anything going wrong with my code? Please help me to find the bug.
Yes that is a mistake. You should check that the array location is valid. Don't count on getting RE in C++.

Re: 10279 - Mine Sweeper

Posted: Mon Dec 08, 2014 5:34 pm
by tidusleonart

Code: Select all

AC
Keep getting WA. Please help me. I print the exact format and everything. i dont kno why i still getting WA....Thanks in advance

Re: 10279 - Mine Sweeper

Posted: Mon Dec 08, 2014 10:39 pm
by brianfry713
Don't read and write outside of array boundaries.

Re: 10279 - Mine Sweeper

Posted: Tue Dec 09, 2014 6:43 pm
by tidusleonart
u mean that i cant use the array as global and memset with 0 right? it will give incorrect answer? can u please explain a bit details ? Thanks

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 1:12 am
by brianfry713
Global and memset are fine.

If i and j are 0 then don't read and write to board[j - 1]

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 3:55 pm
by tidusleonart

Code: Select all

AC
I fixed the out of bound stuff but well still get WA, I have no idea . is there any critical test cases that i miss out? thanks

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 4:42 pm
by lighted
sohel wrote:You have to print a blank line between two consecutive outputs.

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 4:48 pm
by tidusleonart

Code: Select all

 if(check)
         printf("\n");
      check = true;
yes i did. u can test my code with the input...i compare result with others too.. still WA

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 5:16 pm
by lighted
Yes, i see that you did. I didn't notice that because your code contains unnecessary parts like printBoard(int n).
brianfry713 wrote:Don't read and write outside of array boundaries.
You didn't completely performed Brianfry's advice. Your checkings j < n and i < n are not correct. One example how it should be

Code: Select all

(board[i][j+1] < bomb && j + 1 < n) ? board[i][j+1]++: bomb;

Re: 10279 - Mine Sweeper

Posted: Wed Dec 10, 2014 5:41 pm
by tidusleonart
Thanks Brainfry and Lighted. U guys helped me and now i got AC. Thanks so much

Re: 10279 - Mine Sweeper

Posted: Sun Apr 05, 2015 2:59 am
by natan29
Hi,
could any one help why i only got WR every time? I've tested a lot of inputs in my program and in the uDebug and they are both give me the same output. I don't know what i'm doing wrong. This simple problem is blowing my mind :o

Code: Select all

#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
int m,n,h,i,j,k,l,s,q,cont,cont2;

	while(scanf("%d",&m)==1){
      for(h=1;h<=m;h++){
         scanf("%d",&n);
   		char A[n][n],B[n][n],C[n][n];
         
   		for(i=0;i<n;i++){
 				cin>> A[i];
   		}
   		for(i=0;i<n;i++){
   			cin>> B[i];
   		}
   		cont2=0;
   		for(i=0;i<n;i++){       
   				for(j=0;j<n;j++){
                  if(B[i][j]=='x' && A[i][j]=='*'){
                       cont2++;
                  }
                  if (B[i][j]=='x'){
                        k=i-1; l=i+1;
                        s=j-1; q=j+1;
                        				
         					if ( (k>=0 && k<n)&&(s>=0 && s<n) && A[k][s]=='*'){
         						cont++;
         					}
         					if ( (k>=0 && k<n) && A[k][j]=='*'){
         						cont++;
         					}
         					if ( (k>=0 && k<n)&&(q>=0 && q<n) && A[k][q]=='*'){
         						cont++;
         					}
         					if ( (s>=0 && s<n) && A[i][s]=='*'){
         						cont++;
         					}
         					if ( (q>=0 && q<n) && A[i][q]=='*'){
         						cont++;
         					}
         					if ( (l>=0 && l<n) && (s>=0 && s<n) && A[l][s]=='*'){
         						cont++;
         					}
         					if ( (l>=0 && l<n) && A[l][j]=='*'){
         						cont++;
         					}
         					if ( (l>=0 && l<n)&&(q>=0 && q<n) && A[l][q]=='*'){
         						cont++;
         					}
         					
         					C[i][j]=(char)(((int)'0')+cont);
         					cont=0;
                    }
                    if(B[i][j]=='.'){
                          C[i][j]='.';
                    }                 		
              }     
          }
          if(cont2>0){
             for(i=0;i<n;i++){       
      				for(j=0;j<n;j++){
                     if(A[i][j]=='*'){
                         cout<<"*";
                     }
                     else                  
                         cout<<C[i][j];              
                  }
                  printf("\n");
             }
          }
          else{
             for(i=0;i<n;i++){       
      				for(j=0;j<n;j++){
                         cout<<C[i][j];              
                  }
                  printf("\n");
             } 
          }
       printf("\n");
       }    
	}
return 0;
}

Code: Select all

*input*
5

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxx.....
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

4
...*
.*..
....
....
xxx.
xxxx
xxxx
xxx.

2
.*
..
x.
x.

2
**
..
x.
xx

1
.
x

Code: Select all

*output*
001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

112*
1*21
1110
000.

1.
1.

**
22

0



Re: 10279 - Mine Sweeper

Posted: Thu Apr 09, 2015 1:14 am
by brianfry713
Print a blank line between each consecutive 2 consecutive test cases. Don't print an extra blank line at the end.