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

Post Reply
kelvin
New poster
Posts: 1
Joined: Tue Aug 13, 2002 1:41 pm

10279

Post by kelvin »

[pascal] :cry:
I passed the sample but I still got WA
I need help
type
arr=array[1..10,1..10] of char;
var
a:arr;f,n:integer;
procedure ini(n:integer);
var
i,j:integer;
begin
for i:=1 to n do
begin
for j:=1 to n do
read(a[i,j]);
readln;
end;
end;
procedure main(var a:arr);
var
i,j,t:integer;
ch:char;
begin
f:=0;
for i:=1 to n do
begin
for j:=1 to n do
begin
read(ch);
if ch='x' then
if a[i,j]='*' then f:=1
else {if a[i,j]<>'*' then} begin
t:=0;
if ((i-1)>0)and((j-1)>0) then
if a[i-1,j-1]='*' then t:=t+1;
if ((i-1)>0)and(j>0) then
if a[i-1,j]='*' then t:=t+1;
if ((i-1)>0)and((j+1)<n+1) then
if a[i-1,j+1]='*' then t:=t+1;
if (i>0)and((j-1)>0) then
if a[i,j-1]='*' then t:=t+1;
if (i>0)and((j+1)<n+1) then
if a[i,j+1]='*' then t:=t+1;
if ((i+1)<n+1)and((j-1)>0) then
if a[i+1,j-1]='*' then t:=t+1;
if ((i+1)<n+1)and(j>0) then
if a[i+1,j]='*' then t:=t+1;
if ((i+1)<n+1)and((j+1)<n+1) then
if a[i+1,j+1]='*' then t:=t+1;
a[i,j]:=chr(t+ord('0'));
end
// else write('*');
end;
readln;
end;
end;
procedure print(a:arr);
var
i,j:integer;
begin
if f=1 then
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j]);
writeln;
end
else for i:=1 to n do
begin
for j:=1 to n do
if a[i,j] in ['0'..'8']
then write(a[i,j])
else write('.');
writeln;
end;
end;

begin
readln(n);
ini(n);
main(a);
print(a);
readln;
end.[/pascal]
sunkid
New poster
Posts: 1
Joined: Sun Aug 04, 2002 4:26 am

10279

Post by sunkid »

:evil:
i can't pass the 10279!
why???

if the input is:
/************input******/
3

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

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

8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
........
........
........
........
........
........
........
x.......

/****************/

my out put is :
/***************/
001.....
0013....
0001....
00011...
00001...
00123...
001.....
00123...

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

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

is it right!
who can tell me
thank!
wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am

Post by wyvmak »

something strange.
i didn't read the problem statement :-?
but the third case, my output is:

........
........
........
........
........
........
........
0.......
i guess it's the output to:
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
........
........
........
........
........
........
........
x.......
arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 »

sunkid:
wyvmak is right, you only have to print the number of mine only if the current position has been touched ('X'). The others remain blank ('.') except any of the touched position revealed mine.
rjhadley
Learning poster
Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States

Post by rjhadley »

It's a multiple input problem. See http://acm.uva.es/problemset/minput.html.
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

10279

Post by angga888 »

I am sure that my program is working correctly, I still can't pass 602. Why? Any idea? :wink:
What should be the output if 'X' touch '*' ? Should another touched position (number between 0..8) be in output ? or just the mine's position ?
And, please give me unique and creative inputs to check my program.

Thanx for helping me.
Angga :D
deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

umm, I still confused, what happened if the position of 'X' is the same with '*',

in my understanding is the output will be exact the same with the input

am I right????

pls someone clarify this for me
the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Location: Dacca, Bangladesh
Contact:

Post by the LA-Z-BOy »

umm, I still confused, what happened if the position of 'X' is the same with '*', in my understanding is the output will be exact the same with the input
am I right????
no, you aren't! look:
Your output should represent the board, with each position filled in appropriately. Positions that have been touched and do not contain a mine should contain an integer between 0 and 8. If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period.
here "All other positions" means all untouched positions (doesn't matter if you touch a/many mine(s) or not.)
if any mine(s) has been touched then show all mines with asterisks and other unmined touched position with number and rest untouched positions with a period.

try this

Code: Select all

/* Input */
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
xxxxxxxx
xxxx....
xxxx....
xxxxx...
xxxxx...
xxxxx...
xxx.....
xxxxx...

Code: Select all

/* Output */
001**22*
0013..*.
0001*...
00011...
00001...
00123*..
001**.*.
00123*..
Istiaque Ahmed [the LA-Z-BOy]
mrtamtam
New poster
Posts: 5
Joined: Wed Jan 15, 2003 9:50 pm

10279 a easy problem,but why wrong answer?

Post by mrtamtam »

[c]
#include <stdio.h>

int main()
{
int map[100][100];
char str[200];
int n;
int i,j,x,y,ans;
int t1,t2;
char ch;

scanf("%d",&t2);

for (t1=1; t1<=t2; t1++)
{
scanf("%d\n",&n);

if (t1 > 1)
printf("\n");

for (i=0; i <= 20; i++)
for (j=0; j <= 20; j++)
map[j] = 0;

for (i=1; i <= n; i++)
{
gets(str);
for (j=1; j <= n; j++)
{

if (str[j-1] == '*')
map[j] = 1;
else
map[j] = 0;
}
}

for (i=1; i <= n; i++)
{
gets(str);
for (j=1; j <= n; j++)
{
ans = 0;

if (str[j-1] == 'x')
{

if (map[j] == 1)
printf("*");
else
{

ans = 0;
for (x=-1; x <= 1; x++)
for (y=-1; y <= 1; y++)
if (map[i+y][j+x] == 1)
ans++;

printf("%d",ans);

}

}
else
printf(".");

if (j == n)
printf("\n");

}
}
}

return 0;
} [/c]
bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

grrrrr :-(

Post by bery olivier »

I got the same problem, I can't find the inputs that causes that wrong answer. :evil:
Not AC yet Image AC at last Image
Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth

10279 Why WA and WA ???

Post by Daredevil »

consider this input :
4
. . . *
. * * .
. . . .
* * * *
xxx.
xx..
x...
x...
What will the output be?
Output 1
. . . *
. * * .
. . . .
* * * *
Output 2
123.
1**.
3...
****

Or neither of them?, if so what will it be?
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Why you have spaces in input ?
My accepted solution outputs:

123*
1**.
3...
****

Dominik

PS. Did you see blue checkmark near this problem ?(Multiply input)
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth

Post by Daredevil »

I'm aware that this is a multiple input problem. Btw, It's said if a bomb is encountered during the game, ALL POSITION CONTAINING THE BOMB MUST PRINTED '*' AND ALL OTHER POSITION MUST CONTAIN '.'.
Oh, should I print extra blank line between two consecutive outputs?
Thx anyway!!
Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

I don't remember - If specifications say print empty line between cases - print it, otherwise - not print it :)

Dominik
PS. In your input you pick a mine in last row, so you must print all of them .
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)
Daredevil
New poster
Posts: 19
Joined: Tue Apr 01, 2003 7:47 am
Location: Earth

Post by Daredevil »

I've tried everything, but still WA

C :
#include<stdio.h>
#include<string.h>
int i,j,k,l,m,n,sum,yes;
char game[15][15],board[15][15];
void main(){
while(scanf("%i",&n)!=EOF){
for(i=0;i<n;i++){scanf("%s",&board);}
for(i=0;i<n;i++){scanf("%s",&game);}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(game[j]!='.'&&board[j]=='*'){yes=1;break;}
}
}
if(yes==1){
yes=0;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(game[j]!='.'){
if(board[j]=='*'){printf("*");}
else{
k=i-1;m=j-1;
if(k<0){k++;}
if(m<0){m++;}
for(k=k;k<=i+1&&k<n;k++){
for(l=m;l<=j+1&&l<n;l++){
if(board[k][l]=='*'){sum++;}
}
}
printf("%i",sum);sum=0;
}
}
else{
if(board[j]=='*'){printf("*");}
else{printf(".");}
}
}
printf("\n");
}
}
else{
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(game[j]!='.'){
k=i-1;m=j-1;
if(k<0){k++;}
if(m<0){m++;}
for(k=k;k<=i+1&&k<n;k++){
for(l=m;l<=j+1&&l<n;l++){
if(board[k][l]=='*'){sum++;}
}
}
printf("%i",sum);sum=0;
}
else{printf(".");}
}
printf("\n");
}
}
}
}

Could you please tell me where my mistakes?
I'm very frustrated. Thx
Post Reply

Return to “Volume 102 (10200-10299)”