{Kenneth Kang

ACSL Junior Division

Enloe

Contest 4}

Program Flock;

Uses CRT;

Type

      arry=Array[1..10] of char;

Var

   resp:char;

   stage:arry;

   numofbird:integer;

   gener:integer;

 

Procedure setbird(var stage:arry; var numofbird,gener:integer);

Var

      x:integer;

   y:integer;

Begin

      For x:=1 to 10 Do

         stage[x]:='Z';

   Writeln('How many birds are in this flock');

   Readln(numofbird);

   Writeln;

   Writeln('Which spots are the birds in?');

   For y:=1 to numofbird Do

      Begin

            Readln(x);

         stage[x]:='B';

      End;

   Writeln;

   Writeln('How many generations do you want?');

   Readln(gener);

End;

 

Procedure findgener(var stage:arry; var numofbird,gener:integer);

Var

      x:integer;

   y:integer;

   stageori:arry;

Begin

   For y:=1 to gener-1 Do

      Begin

            For x:=1 to 10 Do

               stageori[x]:=stage[x];

            If (stage[1]='Z') and (stage[10]='B') Then

               Begin

                  stage[1]:='B';

               stage[10]:='Z';

            End;

         For x:=1 to 9 Do

               If (stage[x]='B') and (stageori[x]='B') Then

                  Begin

                     If (stage[x+1]='Z') Then

                        Begin

                           stage[x]:='Z';

                        stage[x+1]:='B';

                     End;

               End;

      End;

End;

 

Procedure printinfo(var stage:arry; var numofbird,gener:integer);

Var

      x:integer;

Begin

      Writeln('This is the new position of the flock.');

      For x:=1 to 10 Do

      Begin

            If (stage[x]='B') Then

               Write( x,',')

      End;

End;

 

Begin

   Repeat

      clrscr;

      setbird(stage,numofbird,gener);

      findgener(stage,numofbird,gener);

      Writeln;

      printinfo(stage,numofbird,gener);

      Writeln;

      Writeln;

      writeln('Would you like to run this program again, y/n?');

      readln(resp);

      resp:=Upcase(resp);

   Until (resp<>'Y');

End.