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 1024. Permutations

why i got wrong answer??
Posted by qwt 5 Feb 2002 17:42
var
  a,b:array[1..1000] of integer;
  n,k,i,j:longint;
function over:boolean;
var
  i:integer;
begin
  over:=false;
  for i:=1 to n do if b[i]<>i then exit;
  over:=true;
end;
begin
  readln(n);
  fillchar(a,sizeof(A),0);
  for i:=1 to n do read(a[i]);readln;
  b:=a;
  if over then writeln(0) else begin
    j:=1;
    while over=false do begin
      inc(j);
      for i:=1 to n do
        b[i]:=a[b[i]];
    end;
    writeln(j);
  end;
end.
You have the idea, but your solution isn't correct!(-)
Posted by Miguel Angel 7 Feb 2002 02:48
> var
>   a,b:array[1..1000] of integer;
>   n,k,i,j:longint;
> function over:boolean;
> var
>   i:integer;
> begin
>   over:=false;
>   for i:=1 to n do if b[i]<>i then exit;
>   over:=true;
> end;
> begin
>   readln(n);
>   fillchar(a,sizeof(A),0);
>   for i:=1 to n do read(a[i]);readln;
>   b:=a;
>   if over then writeln(0) else begin
>     j:=1;
>     while over=false do begin
>       inc(j);
>       for i:=1 to n do
>         b[i]:=a[b[i]];
>     end;
>     writeln(j);
>   end;
> end.
>