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
formatting integers
Moderator: Board moderators
-
- New poster
- Posts: 31
- Joined: Sat Nov 17, 2001 2:00 am
- Contact:
Re: formatting integers
Hint: don't use :x (x an integer > 0), unless necessary. I personally like using either :0 or none at all.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
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...
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...
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...