#!/usr/bin/perl

$sf = '[^\:]*\:';
$capture = '([^\:]*)\:';

@grades = ();

while (<>) {
  if (not /^$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf$sf/) {
    print STDERR "Poorly formatted line: $_\n";
  }
  else {
    /^$capture$capture$capture(.*)/; 
    $taname = $1;
    $last = $2;
    $first = $3;
    $rest = $4;

    $rest =~ /^$capture$capture$capture$capture$capture$capture$capture(.*)/;
    $hw = ($1+$2+$3+$4+$5+$6+$7) / (90+90+90+60+60+100+90);
    $rest = $8;

    $rest =~ /^$capture$capture$capture$capture$capture$capture$capture$capture$capture(.*)/;
    $mq = ($1+$2+$3+$4+$5+$6+$7+$8+$9) / (9 * 100);
    $rest = $10;

    $rest =~ /^$capture$capture([^\:]*)/;
    $q1 = $1/70;
    $q2 = $2/100;
    $tut = $3/100;

    $grade = (((.2 * $tut) + (.05 * $mq) + (.35 * $hw) + (.1 * $q1) + (.1 * $q2)) / .8) * 100;

    @grades = (@grades, [ $taname, $last, $first, $grade ]);
  }

}


foreach $p (@grades) {
  printf "%10s %10s %10s  %5.2f\n", $p->[0], $p->[1], $p->[2], $p->[3];
}

print "\n\n";

@slist = sort { -($a->[3] <=> $b->[3]) } @grades;

$i = 0;
foreach $p (@slist) {
  $i++;
  printf "%3d %10s %15s %15s  %5.2f\n", $i, $p->[0], $p->[1], $p->[2], $p->[3];
}
