Page 1 of 1
formatting integers
Posted: Fri May 24, 2002 10:46 am
by xenon
Can anybody tell me how to properly format integers? I get a lot of PEs and sometimes WAs because my code obviously does something wrong.
I don't use gpp on linux, as advised, but always put the ':1' formatter after a number.
In problem 231 I get PE when outputting with:
[pascal] writeln('Test #',testno:1,':');
[/pascal]
and
[pascal] writeln(' maximum possible interceptions: ',max:1);
[/pascal]
(testno and max are integers).
Please tell me how the correct writeln statements should look in these cases...
thx
Re: formatting integers
Posted: Sun Jun 09, 2002 8:23 am
by Ilham Kurnia
xenon wrote:Can anybody tell me how to properly format integers? I get a lot of PEs and sometimes WAs because my code obviously does something wrong.
I don't use gpp on linux, as advised, but always put the ':1' formatter after a number.
In problem 231 I get PE when outputting with:
[pascal] writeln('Test #',testno:1,':');
[/pascal]
and
[pascal] writeln(' maximum possible interceptions: ',max:1);
[/pascal]
(testno and max are integers).
Please tell me how the correct writeln statements should look in these cases...
thx
Hint: don't use :x (x an integer > 0), unless necessary. I personally like using either :0 or none at all.
I'm not quite sure, but probably you get PE because you use to many writeln's. Notice that for P231, you are not asked to put blank line(s) after the last case.
nothing seems to work...
Posted: Sun Jun 09, 2002 9:14 am
by xenon
Thanx for your reply.
But whatever I try (:0, or no formatting at all) I still get PE. And there is no extra blank line after the last case. So for the sake of argument, I'll post my solution for #231:
[pascal]program p231(input,output);
{$IFNDEF ONLINE_JUDGE}
type integer=system.longint;
{$ENDIF}
var
testno,x:integer;
current:array[1..10000] of integer;
max,i:integer;
begin
testno:=0;
repeat
readln(x);
if (x<0) then break;
inc(testno);
if (testno>1) then writeln;
writeln('Test #',testno,':');
max:=1;
current[1]:=x;
repeat
readln(x);
if (x<0) then break;
i:=1;
while ((i<max) and (x<current)) do inc(i);
if ((i=max) and (x<current)) then begin
inc(max);
current[max]:=x;
end
else current:=x;
until false;
writeln(' maximum possible interceptions: ',max);
until false;
end.[/pascal]
I hope anybody can help me out here...
Posted: Sun Jun 09, 2002 11:59 am
by fpnc
Well, our fault here. DO write a blank line at the end of the last case. That is the reason of having PE answers.
A fixing note in the listing of volume 2 is ready.
Sorry!
Posted: Sun Jun 09, 2002 1:31 pm
by xenon
no problem, mate. thx for looking into it.
I encountered more PEs with other problems. I could report them, if you like, but they could as well be caused by programming errors made by myself.
Posted: Sun Jun 09, 2002 4:53 pm
by fpnc
Please, read a private message I've sent to you about this. Thank you!