#!/usr/koeki/bin/ruby # -*- coding: utf-8 -*- # printfの%Xsでの幅を合わせるため require './kprintf.rb' score=[] name =[] sum = 0 while yomikomi = gets if /(\S+)\s+(\d+)/ =~ yomikomi name << $1 score << $2.to_i sum += $2.to_i end end average = sum.to_f/score.length i = 0 print "--氏名--------------+-得点-+-平均との差--\n" while i < score.length printf("%-20s %5d %5.1f\n", name[i], score[i], score[i]-average) i += 1 end