m = /([+-]?\d+)([+-])([+-]?\d+)/.match(gets) a = m[1].to_i b = m[3].to_i if m[2] == '+' p a - b else p a + b end