Created
May 7, 2012 03:55
-
-
Save tkojitu/2625807 to your computer and use it in GitHub Desktop.
okwave.jp/qa/q7454381.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyRecord | |
def initialize(line) | |
@alpha, @number, @value = line.split | |
end | |
attr_reader :alpha, :number, :value | |
end | |
def print_alpha_number(records) | |
num_keys = records.map{|rec| rec.number}.uniq.sort | |
alpha_keys = records.map{|rec| rec.alpha}.uniq.sort | |
$stdout.puts(" " + alpha_keys.join(" ")) | |
num_keys.each do |nkey| | |
$stdout.print(nkey) | |
alpha_keys.each do |akey| | |
$stdout.printf(" %s", find_by_number_alpha(records, nkey, akey).value) | |
end | |
$stdout.puts | |
end | |
end | |
def find_by_number_alpha(records, number, alpha) | |
return records.find{|rec| rec.number == number && rec.alpha == alpha} | |
end | |
$records = [] | |
ARGF.readlines.each{|line| $records << MyRecord.new(line)} | |
print_alpha_number($records) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment