|
|
back to boardwhy 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!(-) > 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. > |
|
|