#!/usr/koeki/bin/ruby # coding: utf-8 defined?(Encoding) && Encoding.default_external = "binary" point = Hash.new while yline = gets if /(\S+)\s+(\d+)\s+(\d+)/ =~ yline # 1個目の() (\S+)→氏名が入る # 2個目の() (\d+)→国語の得点が入る # 3個目の() (\d+)→数学の得点が入る point[$1] = [$2.to_i, $3.to_i] # 配列を代入 end end print "--氏名--------------+-国語-+-数学---\n" for student in point.keys.sort {|x, y| point[x][0] <=> point[y][0] }.reverse # student には、学生の氏名が入っている kokugo = point[student][0] math = point[student][1] printf("%-20s %5d %5d\n", student, kokugo, math) end puts "-"*36