Hi, The following (attached) is a programming problem I've implemented. Now I know the way I've done the EOF test is not correct, otherwise it would not crash with a runtime error of 106.
Could someone show me the correct way of reading from stdin until there is no more input ? cheers James -- - -Zero Defect Software Engineers Group - ZDSEG - -You need only two tools. WD-40 and duct tape. -If it doesn't move and it should, use WD-40. -If it moves and shouldn't, use the tape.
program cycle; function isEven(n: longInt): Boolean; begin if (n MOD 2 = 0) then begin isEven := TRUE; end else begin isEven := FALSE; end; end; function getCycle(n: longInt): longInt; var c: longInt; begin c := 1; while NOT (n = 1) do begin if isEven(n) then begin n := n DIV 2; end else begin n := n * 3 + 1; end; inc(c); end; getCycle := c; end; function getMaxCycle(i: longInt; j: longInt): longInt; var max: longInt; x: longInt; c: longInt; begin max := 0; for c := i to j do begin x := getCycle(c); if (x > max) then begin max := x; end; end; getMaxCycle := max; end; var i: longInt; j: longInt; begin while NOT EOF do begin read(input, i, j); writeLn(getMaxCycle(i, j)); end; end.
1 10 100 200 201 210 900 1000