#!/usr/koeki/bin/ruby a_lunch = 0 b_lunch = 0 while table = gets if /(\S+)\s+(\d+)\s+(\d+)/ =~ table a_lunch += $2.to_i b_lunch += $3.to_i end end nin = a_lunch + b_lunch printf("A ランチ (650 円) %d つ \t B ランチ (550 円) %d つ \t 顧客数 %d 人\n", a_lunch, b_lunch, nin) total = a_lunch * 650 + a_lunch * 550 printf("本日の総売上げ: %d 円 \t 客単価: %5.1f\n", total, total.to_f / nin) if a_lunch > b_lunch printf("A ランチが人気でした\n") elsif a_lunch < b_lunch printf("B ランチが人気でした\n") else printf("同数の注文が出ました\n") end