読者です 読者をやめる 読者になる 読者になる

Tamflexの貯蔵庫

やる気のない備忘録

aoj 0034

contest contest-aoj language language-ruby language-python

鉄道路線 | Aizu Online Judge

練習のためrubypythonで書いてみた

require 'scanf'

while line = gets
  s = line.split(',').map(&:to_i)
  l = s[0..9]
  v1 = s[10]
  v2 = s[11]
  d = l.inject(:+).to_f * v1 / (v1 + v2)
  sum = 0;
  for i in 1..10
    sum += l[i-1]
    if d <= sum
      puts i.to_s
      break
    end
  end
end
import sys

for line in sys.stdin:
    s = map(int, line.split(','))
    l = s[0:10]
    v1 = s[10]
    v2 = s[11]
    d = 1.0*sum(l)*v1/(v1+v2)
    t = 0
    for i in xrange(10):
        t += l[i]
        if t >= d:
            print i+1
            break