10279 - Mine Sweeper

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 10279 - Mine Sweeper

Post by Shahidul.CSE »

Removed after accepted ! :D
Last edited by Shahidul.CSE on Fri Aug 15, 2014 5:30 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post 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++.
Check input and AC output for thousands of problems on uDebug!
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10279 - Mine Sweeper

Post 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
Last edited by tidusleonart on Wed Dec 10, 2014 5:41 pm, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 »

Don't read and write outside of array boundaries.
Check input and AC output for thousands of problems on uDebug!
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10279 - Mine Sweeper

Post 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
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 »

Global and memset are fine.

If i and j are 0 then don't read and write to board[j - 1]
Check input and AC output for thousands of problems on uDebug!
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10279 - Mine Sweeper

Post 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
Last edited by tidusleonart on Wed Dec 10, 2014 5:41 pm, edited 1 time in total.
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10279 - Mine Sweeper

Post by lighted »

sohel wrote:You have to print a blank line between two consecutive outputs.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10279 - Mine Sweeper

Post 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
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10279 - Mine Sweeper

Post 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;
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10279 - Mine Sweeper

Post by tidusleonart »

Thanks Brainfry and Lighted. U guys helped me and now i got AC. Thanks so much
natan29
New poster
Posts: 1
Joined: Sun Apr 05, 2015 2:35 am

Re: 10279 - Mine Sweeper

Post 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


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10279 - Mine Sweeper

Post by brianfry713 »

Print a blank line between each consecutive 2 consecutive test cases. Don't print an extra blank line at the end.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 102 (10200-10299)”