class Yukicoder def initialize s = gets.chomp list = s.chars queue = [] eval_flag = false answer = 0 while !list.empty? ch = list.shift if ch == '+' queue << '*' eval_flag = true elsif ch == '*' queue << '+' eval_flag = true elsif eval_flag queue << ch answer += eval(queue.join) queue = [] eval_flag = false else queue << ch end end puts answer end end Yukicoder.new