Posted: Sat Dec 08, 2007 1:51 am Post subject: Help with test cases. [Pascal]
I was attempting one of the problems from the UVa site, and the judge kept telling me that my program was giving the wrong answer. Hereis the problem.
I don't know how I get the wrong answer. Can someone help :S
Pascal:
uses crt;
var field:array[1..100]ofstring;
outField:array[1..200,1..100,1..100]ofstring;
m,n,x,y,z,count,num:integer;
a,b:array[1..200]ofinteger;
function inBound(i,j:integer):boolean;
begin
inBound:= (i>0)and(i<=100)and(j>0)and(j<=100);
end;
begin
num:=1;
read(n);
readLn(m);
while((n<>0)and(m<>0))do begin for x:=1to n do readLn(field[x]);
for x:=1to n do for y:=1to m do if field[x][y]='.'then begin
count:=0;
if(inBound(x+1,y))and(field[x+1][y]='*')then
count:=count+1;
if(inBound(x+1,y+1))and(field[x+1][y+1]='*')then
count:=count+1;
if(inBound(x,y+1))and(field[x][y+1]='*')then
count:=count+1;
if(inBound(x-1,y))and(field[x-1][y]='*')then
count:=count+1;
if(inBound(x-1,y+1))and(field[x-1][y+1]='*')then
count:=count+1;
if(inBound(x-1,y-1))and(field[x-1][y-1]='*')then
count:=count+1;
if(inBound(x,y-1))and(field[x][y-1]='*')then
count:=count+1;
if(inBound(x+1,y-1))and(field[x+1][y-1]='*')then
count:=count+1;
str(count,outField[num,x,y]);
end else
outField[num,x,y]:='*';
a[num]:=n;
b[num]:=m;
num:=num+1;
read(n);
readLn(m);
end;
for z:=1to num-1do begin writeln('Field #',z,':');
for x:=1to a[z]do begin for y:=1to b[z]do write(outField[z,x,y]);
writeLn;
end;
writeLn;
end;
readln;
end.
Sponsor Sponsor
HeavenAgain
Posted: Sat Dec 08, 2007 8:49 am Post subject: RE:Help with test cases. [Pascal]
try the following test case, i dont know about pascal, but the 2 string array (looks like it) arent really necessary, you just need 1 2-d int array
Field #1:
****11**3*
5**32356*3
**543****4
45***5*7**
**5*43*6*5
*33*212***
//////////////////////blank line
Field #2:
3*3
***
4*4
*3*
///////////////blank line
Field #3:
*1
//////////////////////blank line
Field #4:
0
0
0
1
*
*
1
Quote:
if field[x][y]='.' then
begin
count:=0;
something looks wrong with that line (if i understand it correctly) what if the line doesnt begin with a '.'?
hint: what i think you should do is, read line by line (turn them into int) of the field, if is a '.' leave it, else if it is a '*' make it -1, and now you have a field of bombs in a 2-d int array, and read line by line again (int array) if is 0 leave it, else if it a -1 then increase its sourrounding by 1, BUT be sure not to increase any -1
and for your output case, after each case there should be a blank line, but not the first case, there gl
CodeMonkey2000
Posted: Sat Dec 08, 2007 11:08 am Post subject: RE:Help with test cases. [Pascal]
Your test cases didn't work, but I know why, it's because of the inBounds function. It looked at values that weren't in the scope of my current array.
code:
if field[x][y]='.' then
begin
count:=0;
Oh and field is a single dimensional string array. The second identifier just states what part of the string I should look at. And remember, '.' is an open field, if there is open field, check around for mines, or else draw a mine. Count is the number of mines.
Posted: Sat Dec 08, 2007 7:19 pm Post subject: RE:Help with test cases. [Pascal]
well, its pretty obvious that you dont have to care about the '.', and your focus is on the '*', therefore if you see a '*' you increase its surounding by 1 (but check if there is another '*'). thats it, what do you have problem with? o_O
Er exe files... when you output its impossibile for human eyes (me) to catch it. so i dont know the output so yea... i cant test it and see your output
and ill just repeat my little hint again :p
hint: read each case by the whole, each line you read (input lines) turn them into int 2-d array, if is a '.' then just leave it (because by default int array is 0), else if it is a '*' make the array position of it into -1, and now you have a field of bombs in a 2-d int array, and read line by line again (int array) if is 0 leave it, else if it a -1 then increase its sourrounding by 1, BUT be sure not to increase any -1
and for your output case, after each case there should be a blank line, but not the first case
CodeMonkey2000
Posted: Sat Dec 08, 2007 9:21 pm Post subject: RE:Help with test cases. [Pascal]
My problem is that the judge keeps telling me it's outputting the wrong answer. I tested it with the sample case and your case, and it works fine. So now I'm trying to find out which case it doesn't work for. And it's really frustrating.
Oh did you try to run it from command prompt?
HeavenAgain
Posted: Sat Dec 08, 2007 9:26 pm Post subject: RE:Help with test cases. [Pascal]
yea i just double clicked your program... and for that, i think some judge are picky with answers, dont leave any extra space or any blank lines at the end, sometimes thats the case? and check your out put format i guess
and whats a better way to acually see your output... i enver used pascal
CodeMonkey2000
Posted: Sat Dec 08, 2007 9:45 pm Post subject: RE:Help with test cases. [Pascal]
Open the exe from command prompt. Like how you run C++ exes. I don't think it is a formatting error, I played around with that a lot. Back in my day we use to read from text file and output to text files. And that's the way we liked it. Little to no formation involved.
HeavenAgain
Posted: Sat Dec 08, 2007 9:55 pm Post subject: RE:Help with test cases. [Pascal]
dam it, its really hard to see, you have the right answer, but I think, you are printing out a blank line fore Field #x: you did that for the first line and the last line?
if the test case were
1 1
.
2 2
..
..
0 0
yours output
Quote:
/////blankline <<<< shouldnt be here
Field #1:
0
/////blankline
Field #2:
00
00
/////blankline<<<< shouldnt be here too
Sponsor Sponsor
CodeMonkey2000
Posted: Sat Dec 08, 2007 10:00 pm Post subject: RE:Help with test cases. [Pascal]
I tried that and it still doesn't like it. I'm pretty confident in my answer though. I tried the programming challenges judge, and it can't even compile it.
HeavenAgain
Posted: Sat Dec 08, 2007 10:06 pm Post subject: RE:Help with test cases. [Pascal]
i think it could be your array of string problem then, if the case is VERY big, your array cant handle it
thats my best guess
edit, oh so you just jumped to this problem right away? normally if you are new to a judge site, you should try their easiest probem, just to get the feel of the judge, at least thats what i do...
CodeMonkey2000
Posted: Sat Dec 08, 2007 10:12 pm Post subject: RE:Help with test cases. [Pascal]
This is the first problem on the site, and it is pretty easy. This also happens to be the first problem in the textbook.
HeavenAgain
Posted: Sat Dec 08, 2007 10:14 pm Post subject: RE:Help with test cases. [Pascal]
100 - The 3n + 1 problem , isnt that the first one? that minesweeper is like 10000 something, no idea how they sorted it.... but have you tryed the array one? worked? because you are just assuming the array is going to be this big, instead of err you know, reading it from the first 2 number given (everytime)
CodeMonkey2000
Posted: Sat Dec 08, 2007 10:21 pm Post subject: RE:Help with test cases. [Pascal]
The array one?
Oh and the 3n+1 is the first one but I keep getting a run time error when the upper is 1 to 999999
HeavenAgain
Posted: Sat Dec 08, 2007 10:28 pm Post subject: RE:Help with test cases. [Pascal]
i mean, fixing your array for the minesweeper question, as in if input is
2 3
...
***
read first line let 2 be x and 3 be y
make array of 2 d int array, [x][y] as the size
instead of 1.. 200 you have up there
and for runtime error, maybe is because you are using integer? is there a data type called long? integer might be too small for 999,999 with 6 digits
CodeMonkey2000
Posted: Sat Dec 08, 2007 10:32 pm Post subject: RE:Help with test cases. [Pascal]
The error I get is 216, which is general protection fault. And yea I am using longInt.