|  | 
|  | 
| вернуться в форум | Why my program does not work? I don't no why my program get Wrong Answer???There is my program:
 
 const maxn = 100000;
 var n,i,max,st: longint;
 a: array [0..maxn] of longint;
 begin
 read(n);
 fillchar(a,Sizeof(a),0);
 a[0]:=0; a[1]:=1; st:=0;
 while n <> 0 do begin
 for i:=st to n do begin
 a[2*i]:=a[i]; a[2*i+1]:=a[i]+a[i+1]; end;
 max:=1;
 for i:=0 to n do if a[i] > a[max] then max:=i;
 write(a[max]); if n > st then st:=n;
 read(n);
 end;
 end.
That's easy!(+) First, change write to writeln.Then you'll get CRASH, because in a[2*i+1]:=.. i can be 100000, so,
 you should have an array not [0..100000], but [0..200001].
 
 Good luck!
Re: That's easy!(+) Thank you! | 
 | 
|