10279 - Mine Sweeper
Moderator: Board moderators
10279
[pascal]
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]
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]
10279
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!
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.......
i didn't read the problem statement
but the third case, my output is:
........
........
........
........
........
........
........
0.......
i guess it's the output to:
8
...**..*
......*.
....*...
........
........
.....*..
...**.*.
.....*..
........
........
........
........
........
........
........
x.......
It's a multiple input problem. See http://acm.uva.es/problemset/minput.html.
10279
I am sure that my program is working correctly, I still can't pass 602. Why? Any idea?
What should be the output if 'X' touch '*' ? Should another touched position (number between 0.. 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
What should be the output if 'X' touch '*' ? Should another touched position (number between 0.. 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
-
- Learning poster
- Posts: 94
- Joined: Wed Jul 31, 2002 12:44 pm
- Location: Dacca, Bangladesh
- Contact:
no, you aren't! look: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????
here "All other positions" means all untouched positions (doesn't matter if you touch a/many mine(s) or not.)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.
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]
10279 a easy problem,but why wrong answer?
[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]
#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]
-
- Learning poster
- Posts: 90
- Joined: Sat Feb 15, 2003 1:39 am
- Location: Paris, France
- Contact:
grrrrr :-(
I got the same problem, I can't find the inputs that causes that wrong answer.
Not AC yet AC at last
10279 Why WA and WA ???
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?
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?
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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)
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)
Born from ashes - restarting counter of problems (800+ solved problems)
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
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 .
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)
Born from ashes - restarting counter of problems (800+ solved problems)
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
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