ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1404. Easy to Hack!

Timelimit in 3rd Test :(
Posted by Rh1N0 19 Feb 2007 16:27
Why timelimit on 3rd test?
My program listing:

program hack;
var
ar : array[1..100] of byte;
i,n : integer;
word : string;
begin
readln(word);
n := length(word);
for i:=1 to n do
    begin
         ar[i] := ord(word[i]) - 97;
    end;

begin
      for i:=2 to n do
      begin
           if ar[i] < ar[i-1] then
           while ar[i] < ar[i-1] do ar[i]:= ar[i] + 26;
      end;
end;
for i:= 0 to n-2 do
    begin
         ar[n-i] := ar[n-i] - ar[n-i-1];
    end;
ar[1] := ar[1] - 5;

for i := 1 to n do
    begin
         word[i] := chr(97+ar[i]);
    end;

writeln(word);
end.
Re: Timelimit in 3rd Test :(
Posted by KIRILL(ArcSTU) 19 Feb 2007 17:33
ar : array[1..100] of byte;
Your array overflow

while ar[i] < ar[i-1] do ar[i]:= ar[i] + 26;
this cycle becomes infinity

Example
ar[1]:=240+26 =10

Edited by author 19.02.2007 17:34