#!c:\Program Files\Perl\perl 

$count=0;
$average=0;


print "\n\nThis PERL program calculates the AVERAGE times ";
print "for an arbitrary number of runners!!!\n\n";

do	{	print "Enter the time for runner $count (in minutes) (DONE to exit):";
		chomp($runtimes[$count]=<STDIN>);
		$count++;
	}
	while ($runtimes[$count-1] ne "DONE" && $runtimes[$count-1] ne "done");

$count--;

pop(@runtimes);

for ($i = 0; $i <=$count; $i++)
	{	$average += $runtimes[$i];    }

if ($count >0) {  $average /= $count; }
else {   $average = 0;  }

@runtimes = sort{$a <=> $b}(@runtimes);

($first,$second,$third,@runtimes)=@runtimes;

$last = pop(@runtimes);

print "Average runtime=$average\n";
if ($count >0) { print "\n\nFirst place: $first (minutes)\n"; }
if ($count >1) {print "\t Second place: $second (minutes)\n";  }
if ($count >2) {print "\t\t Third place: $third (minutes)\n";  }
if ($count >3) {print "\t\t\t Last place: $last (minutes)\n";  }



