#!/usr/koeki/bin/ruby # coding: utf-8 point = Hash.new sum = 0 while yline = gets if /(\S+)\s+(\d+)/ =~ yline point[$1] = $2.to_i sum += point[$1] end end average = sum.to_f/point.length print "--氏名--------------+-得点-+-平均との差--\n" for student, pt in point printf("%-20s %5d %5.1f\n", student, pt, pt-average) end