0
0

More than 5 years have passed since last update.

とある世界のタクシー料金 #yhpg

Last updated at Posted at 2015-04-18

METER[elem][:dist]が10で割り切れないのは街の真上でメーターが上がらないようにするためであることに気づいたのはテストを通した後だった.
あと,1箇所でしか使わないのになぜわざわざtrue.to_iとfalse.to_iを定義したのか謎(※colorを誤って発点で判定していた名残).

hena30.rb
#!/usr/bin/env ruby
#http://qiita.com/Nabetani/items/c70417d384720a3339d6
#http://nabetani.sakura.ne.jp/hena/ord30taxi/

class TrueClass
    def to_i() 1 end
end
class FalseClass
    def to_i() 0 end
end

DIST={
    'AB'=>[1090,0],
    'AC'=>[180,0],
    'AD'=>[540,1],
    'BC'=>[960,0],
    'BG'=>[1270,0],
    'CD'=>[400,1],
    'CF'=>[200,0],
    'DE'=>[720,1],
    'DF'=>[510,1],
    'EG'=>[1050,1],
    'FG'=>[230,1],
}
METER=[
    {:dist=>995,:cost=>400},{:dist=>845,:cost=>350}
]
DIFF=[60,50]

if __FILE__==$0
    while gets
        line=$_.chomp.chars.each_cons(2).to_a
        cost=dist=0
        meter=METER[('C'<line[0][0]).to_i]
        cost=meter[:cost]
        dist=meter[:dist]
        line.each{|e|
            d,color=DIST[e.sort.join]
            dist-=d
            while dist<0
                cost+=DIFF[color]
                dist+=200
            end
        }
        p cost
        STDOUT.flush
    end
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0