#!/usr/bin/perl -wn use strict; # @title = qw(A B C D E); my ($sum, $full, $final, $makeup, $total, $i); my (@class_full) = qw(30 30 30 30 30); my ($id, $name, $grade, undef, $fm) = split /:/; if ($id =~ /^\w+\s*$/ and defined $fm) { chomp $fm; my (@g) = split " ", $grade; # 計算平時成績 $sum = $full = 0.0; for ($i=0; $i<=$#g; ++$i) { next if not $g[$i] =~ /^\d+$/; $sum += $g[$i]; $full += $class_full[$i]; } $sum *= 80.0 / $full; # 平時成績達 38 分者及格 my ($pass_grade) = 38; my ($pass) = $sum >= $pass_grade; my ($pf) = $sum; # 期末考 & 補考成績 ($final, $makeup) = split " ", $fm; # 補考的同學... if (not $pass) { $makeup = 0 unless $makeup =~ /^\d+$/; $total = $sum + $makeup * 45.0 / 45; $pass = 1 if $total >= 56; } # 期末考, 或通過補考的同學 if ($pass) { $pf = $pass_grade if $pf < $pass_grade; $final = 0 unless $final =~ /^\d+$/; $total = $pf + $final * 34.0 / 34; $total = 60 + ($total - $pass_grade) * (100 - 60) / (100 - $pass_grade); } printf "$id:$name:$grade: %4.1f %s :$fm : %2d\n", $sum, ($sum>=$pass_grade) ? '過':'補', int($total+0.5); } else { print; }