class Yukicoder def initialize s = gets.chomp list = s.split(/(\+|\*)/) 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 = [answer] else queue << ch end end puts answer end end Yukicoder.new