Thierry Coq schreef:
Thank you guys,
Has somebody here delivered a successful pascal program to the UVa
online judge: http://icpcres.ecs.baylor.edu/onlinejudge/index.php ?
Test problem 100:
http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36
I just succesfully submitted and passed this test problem. See
attachment for source code.
Vincent
program the3nplus1problem;
{$mode objfpc}{$H+}
function CalculateMaxCycleLength(first, last: integer): integer;
var
startcycle: integer;
cycleLength: integer;
n: integer;
begin
result := 0;
if (first>last) then begin
n := first;
first := last;
last := n;
end;
for startcycle := first to last do
begin
cycleLength := 0;
n:=startcycle;
repeat
inc(cyclelength);
if (n=1) then break;
if odd(n) then
n := 3 * n + 1
else
n := n div 2;
until false;
if cycleLength>result then
result := cycleLength;
end;
end;
var
i,j: integer;
MaxCycleLength: LongInt;
begin
while not eof do
begin
readln(i,j);
MaxCycleLength := CalculateMaxCycleLength(i,j);
writeln(i,' ',j,' ',MaxCycleLength);
end;
end.
_______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus