![:D](./images/smilies/icon_biggrin.gif)
10279 - Mine Sweeper
Moderator: Board moderators
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 10279 - Mine Sweeper
Removed after accepted ! ![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
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
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
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10279 - Mine Sweeper
Yes that is a mistake. You should check that the array location is valid. Don't count on getting RE in C++.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.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 10279 - Mine Sweeper
Code: Select all
AC
Last edited by tidusleonart on Wed Dec 10, 2014 5:41 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10279 - Mine Sweeper
Don't read and write outside of array boundaries.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 10279 - Mine Sweeper
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
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10279 - Mine Sweeper
Global and memset are fine.
If i and j are 0 then don't read and write to board[j - 1]
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!
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 10279 - Mine Sweeper
Code: Select all
AC
Last edited by tidusleonart on Wed Dec 10, 2014 5:41 pm, edited 1 time in total.
Re: 10279 - Mine Sweeper
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
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 10279 - Mine Sweeper
Code: Select all
if(check)
printf("\n");
check = true;
Re: 10279 - Mine Sweeper
Yes, i see that you did. I didn't notice that because your code contains unnecessary parts like printBoard(int n).
You didn't completely performed Brianfry's advice. Your checkings j < n and i < n are not correct. One example how it should bebrianfry713 wrote:Don't read and write outside of array boundaries.
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
-
- New poster
- Posts: 10
- Joined: Fri Nov 21, 2014 9:18 am
Re: 10279 - Mine Sweeper
Thanks Brainfry and Lighted. U guys helped me and now i got AC. Thanks so much
Re: 10279 - Mine Sweeper
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
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](./images/smilies/icon_eek.gif)
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
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10279 - Mine Sweeper
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!