formatting integers

Write here if you have problems with your Pascal source code

Moderator: Board moderators

Post Reply
xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

formatting integers

Post 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
Ilham Kurnia
New poster
Posts: 31
Joined: Sat Nov 17, 2001 2:00 am
Contact:

Re: formatting integers

Post 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.
xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

nothing seems to work...

Post 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...
fpnc
System administrator
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

Post 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!
Best regards,

Fernando N
xenon
Learning poster
Posts: 100
Joined: Fri May 24, 2002 10:35 am
Location: Scheveningen, Holland

Post 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.
fpnc
System administrator
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

Post by fpnc »

Please, read a private message I've sent to you about this. Thank you!
Best regards,

Fernando N
Post Reply

Return to “Pascal”