Codeforces 151 B. Phone Numbers

問題

n人の人の電話帳のデータが与えられる。
電話番号のうち、
全ての桁が同じ数字のものはタクシーの番号であり、
全ての桁が降順に並んでいるものは、ピザ屋の番号であり、
その他の番号は全てガールフレンドの番号である。


タクシーの番号、ピザ屋の番号、ガールフレンドの番号それぞれを、
最も知っている人の名前を出力せよ。
タイの場合は、,で区切って全て出力せよ。(順番は、問題で与えられた順とする)

制約条件

n≦100
それぞれの電話帳の電話の個数≦100

方針

定義に従って実装すればいい。
rubyで書いてみた。
けどなんか綺麗に書けなかった。

ソースコード

person = []
gets.to_i.times{ |i|
 a, b = gets.split
 person[i] = [b, 0, 0, 0]
 a.to_i.times{
  d = gets.gsub(/[^\d]/, "").split("").map(&:to_i)
  same, dec = true, true
  d.each_with_index{ |x,j|
   same = false if x != d[0]
   dec = false if j > 0 && x >= d[j-1]
  }
  if same
   person[i][1] += 1
  elsif dec
   person[i][2] += 1
  else
   person[i][3] += 1
  end
 }
}

mx = (1..3).map{ |i| person.max_by{ |e| e[i] }[i] }
["call a taxi" ,"order a pizza", "go to a cafe with a wonderful girl"].each_with_index{ |s,i|
 puts "If you want to " + s + ", you should call: " +
 person.select{ |e| e[i+1] == mx[i] }.map{ |e| e[0] }*", " + "."
}