D = 10 wn_sum = 0 dn_sum = 0 gets while line = gets do case line when /(-?)(\d+)\.(\d+)/ then sign, wn, dn = $1, $2.to_i, $3.ljust(D, "0").to_i when /(-?)(\d+)/ sign, wn, dn = $1, $2.to_i, 0 end if sign == "-" then wn_sum -= wn dn_sum -= dn else wn_sum += wn dn_sum += dn end end puts (wn_sum * 10 ** D + dn_sum).to_s.insert(-D-1, ".")