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 1022. Genealogical Tree

Compilation error in Pascal
Posted by TUIT_MAD 4 Mar 2008 06:48
program mars;
uses crt;
var a,b:array[1..100] of integer;
    i,j,k,n,max,min,s,p:integer;
begin
   clrscr;
  {Vvod}
  readln(n); s:=0;
  for i:=1 to n do
  begin
    for j:=1 to n-1 do
    begin
      {write('a[',j,']=');} read(a[j]);
      if a[j]=0 then
      begin
        for k:=j to n-1 do
        a[k]:=0;
        j:=k;
      end;
     s:=s+a[j];
    end;
    b[i]:=s;
    s:=0;
  end;
  {Sortirovka i vivod}
  min:=b[1];
  for i:=1 to n do
    if b[i]<=min then begin min:=b[i]; p:=i; end;
  for j:=1 to n do
  begin
    max:=b[1];
    for i:=1 to n do
    begin
      if b[i]>max then begin max:=b[i]; a[j]:=i; k:=i; end;
    end;
    b[k]:=0;
  end;
  a[n]:=p;
  for i:=1 to n do
    write(a[i],' ');
readkey;
end.
Re: Compilation error in Pascal (+)
Posted by Orlangur [KNU] 4 Mar 2008 18:31
You tried to solve problem 1022 Genealogical tree.
Your solution was compiled with the following errors:

8421e763-05ba-4aea-b470-f7f9a3d55a5e(16,5) Error: Illegal assignment to for-loop variable "j"
8421e763-05ba-4aea-b470-f7f9a3d55a5e(39,4) Fatal: There were 1 errors compiling module, stopping
8421e763-05ba-4aea-b470-f7f9a3d55a5e(39,4) Fatal: Compilation aborted


You cannot modify iterator in for-loop directly, replace

for j:=1 to 2 do
begin
if 1=2 then j := 3;
end;

with

j := 1;
while j <= 2 do
begin
if 1=2 then j := 3;
inc(j);
end;

And don't use unit crt, read FAQ about how to do input/output.