10189 - Minesweeper
Moderator: Board moderators
-
- Learning poster
- Posts: 67
- Joined: Sun Sep 22, 2002 5:40 am
- Location: Taiwan
10189 Easy but dunno why wrong answer....sigh.....
this is an easy one........ but I still always get wrong answer when submitting to the online judge, I have tested the program with some cases and getting all-correct result.
May anyone please help me to see what's go wrong....?? thanks!!
[c]
/* @JUDGE_ID: 27296JC 10189 C "aaa" */
/* CSC1140@ 02759173 jl3Rjjtv 10189*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
/* height and width store the input height and width of the board */
int i, j, height, width, cno;
/* the board stores the minesweeper board */
char board[200][200];
char temp[200][200];
for(cno = 0; ; cno++)
{
/* get the height and width of the first board */
scanf("%d %d", &height, &width);
if(height == 0 && width == 0)
break;
if(cno > 0)
printf("\n");
/* get the input board */
for (i=0; i< height; i++)
scanf("%s", board);
for (i=0; i<200; i++){
for (j=0;j<200; j++){
temp[j]=48;
}
}
for (i=0;i<width;i++){
for (j=0;j<height;j++){
if (board[j]=='*'){
if (i>0 && j>0 && board[i-1][j-1]!='*'){ temp[i-1][j-1]+=1;}
if (j>0 && board[j-1]!='*'){ temp[j-1]+=1;}
if (i<200-1 && j>0 && board[i+1][j-1]!='*'){ temp[i+1][j-1]+=1;}
if (i>0 && board[i-1][j]!='*'){ temp[i-1][j]+=1;}
if (i<200-1 && board[i+1][j]!='*') {temp[i+1][j]+=1;}
if (i>0 && j<200-1 && board[i-1][j+1]!='*'){ temp[i-1][j+1]+=1;}
if (j<200-1 && board[j+1]!='*') {temp[j+1]+=1;}
if (j<200-1 && board[i+1][j+1]!='*') {temp[i+1][j+1]+=1;}
temp[j]='*';
}
}
}
printf("Field #%d:\n", cno + 1);
for (i=0; i< height; i++)
{
for (j=0; j< width; j++)
printf("%c", temp[j]);
printf("\n");
}
}
return 0;
}
[/c]
May anyone please help me to see what's go wrong....?? thanks!!
[c]
/* @JUDGE_ID: 27296JC 10189 C "aaa" */
/* CSC1140@ 02759173 jl3Rjjtv 10189*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
/* height and width store the input height and width of the board */
int i, j, height, width, cno;
/* the board stores the minesweeper board */
char board[200][200];
char temp[200][200];
for(cno = 0; ; cno++)
{
/* get the height and width of the first board */
scanf("%d %d", &height, &width);
if(height == 0 && width == 0)
break;
if(cno > 0)
printf("\n");
/* get the input board */
for (i=0; i< height; i++)
scanf("%s", board);
for (i=0; i<200; i++){
for (j=0;j<200; j++){
temp[j]=48;
}
}
for (i=0;i<width;i++){
for (j=0;j<height;j++){
if (board[j]=='*'){
if (i>0 && j>0 && board[i-1][j-1]!='*'){ temp[i-1][j-1]+=1;}
if (j>0 && board[j-1]!='*'){ temp[j-1]+=1;}
if (i<200-1 && j>0 && board[i+1][j-1]!='*'){ temp[i+1][j-1]+=1;}
if (i>0 && board[i-1][j]!='*'){ temp[i-1][j]+=1;}
if (i<200-1 && board[i+1][j]!='*') {temp[i+1][j]+=1;}
if (i>0 && j<200-1 && board[i-1][j+1]!='*'){ temp[i-1][j+1]+=1;}
if (j<200-1 && board[j+1]!='*') {temp[j+1]+=1;}
if (j<200-1 && board[i+1][j+1]!='*') {temp[i+1][j+1]+=1;}
temp[j]='*';
}
}
}
printf("Field #%d:\n", cno + 1);
for (i=0; i< height; i++)
{
for (j=0; j< width; j++)
printf("%c", temp[j]);
printf("\n");
}
}
return 0;
}
[/c]
10196 - Check The Check
Dear EVERYONE!
I'm am not sure how to send my programs into the ACM grader...
Here is my program from MINESWEEPER , ID # 10189
Please Help me Find out what is Wrong!
its keeps saying Compiner Error
[c]
#include<stdio.h>
int m,n;
char field[100][100]={0};
int map [100][100]={0};
main()
{
int i,j;
char ch;
scanf("%d%d",&m,&n);
while(( m != 0) && ( n!=0 ))
{
//RESET//
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{field[j]=0;
map[j]=0;}
//INPUT//
for(i=1;i<=m;i++)
{ scanf("%c",&ch);
for(j=1;j<=n;j++)
scanf("%c",&field[j]);}
//WORK//
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(field[j] == '*')
{ map[i+1][j+0] ++;
map[i+1][j+1] ++;
map[i+1][j-1] ++;
map[i+0][j+1] ++;
map[i+0][j-1] ++;
map[i-1][j+0] ++;
map[i-1][j+1] ++;
map[i-1][j-1] ++;}
//OUTPUT//
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
if(field[j] == '*') printf("*");
else printf("%d",map[j]);
printf("\n");}
scanf("%d%d",&m,&n);
}
}[/c]
errrrrrrrr why won't it work!
I'm am not sure how to send my programs into the ACM grader...
Here is my program from MINESWEEPER , ID # 10189
Please Help me Find out what is Wrong!
its keeps saying Compiner Error
[c]
#include<stdio.h>
int m,n;
char field[100][100]={0};
int map [100][100]={0};
main()
{
int i,j;
char ch;
scanf("%d%d",&m,&n);
while(( m != 0) && ( n!=0 ))
{
//RESET//
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{field[j]=0;
map[j]=0;}
//INPUT//
for(i=1;i<=m;i++)
{ scanf("%c",&ch);
for(j=1;j<=n;j++)
scanf("%c",&field[j]);}
//WORK//
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(field[j] == '*')
{ map[i+1][j+0] ++;
map[i+1][j+1] ++;
map[i+1][j-1] ++;
map[i+0][j+1] ++;
map[i+0][j-1] ++;
map[i-1][j+0] ++;
map[i-1][j+1] ++;
map[i-1][j-1] ++;}
//OUTPUT//
for(i=1;i<=m;i++)
{for(j=1;j<=n;j++)
if(field[j] == '*') printf("*");
else printf("%d",map[j]);
printf("\n");}
scanf("%d%d",&m,&n);
}
}[/c]
errrrrrrrr why won't it work!
Last edited by AllanLin on Sun Jun 29, 2003 3:55 am, edited 1 time in total.
-
- Experienced poster
- Posts: 202
- Joined: Fri Mar 22, 2002 2:00 am
- Location: Chittagong. CSE - CUET
- Contact:
Welcome! Allan!
I have compiled your code and got only one warning.........
your main function should return a value........
One very important thing.............
Try to post your threads in the related topic..........you may use the volume or language C section for this.........
Carry on
I have compiled your code and got only one warning.........
your main function should return a value........
One very important thing.............
Try to post your threads in the related topic..........you may use the volume or language C section for this.........
Carry on
We are all in a circular way, no advances, only moving and moving!
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Thank You Everyone
I am very lucky to decided to start this ACM training. I have complety amazed with everyone!
Everyone Cares.. and helps those in need.
Thank You! You Guys the best
Yours
Allan Lin
Everyone Cares.. and helps those in need.
Thank You! You Guys the best
Yours
Allan Lin
10189 W.A
[cpp]//10189
#include<stdio.h>
main()
{
char in[100][100],out[100][100];
int n,m,i=0,j=0,now=1;
while(scanf("%d%d%*c",&n,&m)==2)
{
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%c",&in[j]);
out[j]='0';
}
scanf("%*c");
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(in[j]=='*')
{
out[j]=in[j];
if(i>0&&in[i-1][j]!='*')
out[i-1][j]++;
if(i+1<=n&&in[i+1][j]!='*')
out[i+1][j]++;
if(j+1<=m&&in[j+1]!='*')
out[j+1]++;
if(j>0&&in[j-1]!='*')
out[j-1]++;
if(i>0&&j>0&&in[i-1][j-1]!='*')
out[i-1][j-1]++;
if(i+1<n&&j>0&&in[i+1][j-1]!='*')
out[i+1][j-1]++;
if(i>0&&j<m&&in[i-1][j+1]!='*')
out[i-1][j+1]++;
if(i<n&&j<m&&in[i+1][j+1]!='*')
out[i+1][j+1]++;
}
}
printf("Field #%d:\n",now);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%c",out[j]);
printf("\n");
}
printf("\n");
now++;
}
}[/cpp]
Anyone can help.
I got W.A.
Thanks
#include<stdio.h>
main()
{
char in[100][100],out[100][100];
int n,m,i=0,j=0,now=1;
while(scanf("%d%d%*c",&n,&m)==2)
{
if(n==0&&m==0)
break;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%c",&in[j]);
out[j]='0';
}
scanf("%*c");
}
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
if(in[j]=='*')
{
out[j]=in[j];
if(i>0&&in[i-1][j]!='*')
out[i-1][j]++;
if(i+1<=n&&in[i+1][j]!='*')
out[i+1][j]++;
if(j+1<=m&&in[j+1]!='*')
out[j+1]++;
if(j>0&&in[j-1]!='*')
out[j-1]++;
if(i>0&&j>0&&in[i-1][j-1]!='*')
out[i-1][j-1]++;
if(i+1<n&&j>0&&in[i+1][j-1]!='*')
out[i+1][j-1]++;
if(i>0&&j<m&&in[i-1][j+1]!='*')
out[i-1][j+1]++;
if(i<n&&j<m&&in[i+1][j+1]!='*')
out[i+1][j+1]++;
}
}
printf("Field #%d:\n",now);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%c",out[j]);
printf("\n");
}
printf("\n");
now++;
}
}[/cpp]
Anyone can help.
I got W.A.
Thanks
Increase your array (out) size to 101.
On a 100x100 board, you sometimes attempt to increase out[x][100], which in memory is the same as out[x+1][0] and is thus incrementing something you don't want to.
Also, you can make the array size 102 and start everything at 1, so you don't have to worry about indexes going below 0 as well, and eliminate the bounds checking altogether.
Alternatively, you can just fix your bounds checking, but the above recommendation is probably quicker.
On a 100x100 board, you sometimes attempt to increase out[x][100], which in memory is the same as out[x+1][0] and is thus incrementing something you don't want to.
Also, you can make the array size 102 and start everything at 1, so you don't have to worry about indexes going below 0 as well, and eliminate the bounds checking altogether.
Alternatively, you can just fix your bounds checking, but the above recommendation is probably quicker.
-
- Guru
- Posts: 647
- Joined: Wed Jun 26, 2002 10:12 pm
- Location: Hong Kong and New York City
- Contact:
A cleaner way to write this instead of all those statements are:
Makes it easier to read/write and less error prone..
Code: Select all
int dx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
int dy[] = { 1, -1, 0, 1, -1, 1, 0, -1 };
for ( i = 0; i < 8; i++ )
/* Check stuff with x + dx[i] and y + dy[i] */
10189 - Minesweeper: AC but still...
Look at the response i got after submitting the solution:
[BEGIN]
Your C++ program has solved Ok the problem 10189 (Minesweeper)
in 0.018 seconds with low memory spent.
Congratulations!
Warning: Your program would get a Presentation Error in a true contest.
The 24-hours judge interpretes it as an "Accepted" problem.
[END]
What does this really mean? I should also mention that i got
WA at http://www.programming-challenges.com. Weird.
--
Tore Nedretvedt
[BEGIN]
Your C++ program has solved Ok the problem 10189 (Minesweeper)
in 0.018 seconds with low memory spent.
Congratulations!
Warning: Your program would get a Presentation Error in a true contest.
The 24-hours judge interpretes it as an "Accepted" problem.
[END]
What does this really mean? I should also mention that i got
WA at http://www.programming-challenges.com. Weird.
--
Tore Nedretvedt
-
- Experienced poster
- Posts: 145
- Joined: Sat Feb 23, 2002 2:00 am
- Location: Paris, France
- Contact:
Hi Tore
PE (or Presentation Error) happens when you've got presentation problems, such as leading or trailing white spaces or new lines, or sometimes trickier errors (but rarely, designing a judge able to deal with complicated errors of that kind is tricky). At the real time contest, you'd have WA.
Programming challenges isn't as nice as uva, talking about PE or even in general : look at its board : very many people are complaining about uva's AC problems, and WA on p-c. I agree that p-c might be testing some trickier input than uva, but it doesn't explain why SO MANY problems arise. Problems in latency time in answers, or running time much slower than UVA, etc, are also reported.
I've been really disapointed by programming-challenges. In my opinion, The book is as good as the site is bad : while the book is good, with a few bad points, the site is bad, with a (very) few good points.
So let's take best of both worlds : Programming challenges Book, and UVA website
To conclude on P-c, I would say that it is a fairly good introduction to Skiena's reference : Algorithm design manual. I learned a lot by beginning a subject with p-c and goind deeper with adm (for Dynamic Programming, specially).
PE (or Presentation Error) happens when you've got presentation problems, such as leading or trailing white spaces or new lines, or sometimes trickier errors (but rarely, designing a judge able to deal with complicated errors of that kind is tricky). At the real time contest, you'd have WA.
Programming challenges isn't as nice as uva, talking about PE or even in general : look at its board : very many people are complaining about uva's AC problems, and WA on p-c. I agree that p-c might be testing some trickier input than uva, but it doesn't explain why SO MANY problems arise. Problems in latency time in answers, or running time much slower than UVA, etc, are also reported.
I've been really disapointed by programming-challenges. In my opinion, The book is as good as the site is bad : while the book is good, with a few bad points, the site is bad, with a (very) few good points.
So let's take best of both worlds : Programming challenges Book, and UVA website
To conclude on P-c, I would say that it is a fairly good introduction to Skiena's reference : Algorithm design manual. I learned a lot by beginning a subject with p-c and goind deeper with adm (for Dynamic Programming, specially).
OK, thanks for the tip. Just another thing about PE. I've experienced
PE for one problem when I wrote a new line after the last output, and then got it fixed when I removed it. But, to the contrary, I've also experienced PE for another problem when I didn't write a newline after the last output, and then got it fixed by outputing a newline at the end. Go figure.
--
Tore Nedretvedt
PE for one problem when I wrote a new line after the last output, and then got it fixed when I removed it. But, to the contrary, I've also experienced PE for another problem when I didn't write a newline after the last output, and then got it fixed by outputing a newline at the end. Go figure.
--
Tore Nedretvedt