fork download
  1. while s = gets and s != "end\n"
  2. a, op, b = *s.split
  3. a, b = *[a, b].map { |t| t =~ /\./ ? t.to_f : t.to_i }
  4.  
  5. result = case op
  6. when '+' then a + b
  7. when '-' then a - b
  8. when '*' then a * b
  9. when '/' then a / b
  10. when '%' then a % b
  11. end
  12.  
  13. puts result.is_a?(Float) ? result.round(3) : result
  14. end
Success #stdin #stdout 0.05s 9768KB
stdin
2 + 3
4.1 + 8.2
5 - 6
5.241 - 2.2
2 * 5
3.1 * 2
6 * -7
7 / 3
-7 / 3
7 / -3
7.0 / 3
2 / 0.0
-2.0 / 0
0.0 / 0.0
7 % 3
-7 % 3
7 % -3
end
1234567890 + 0
stdout
5
12.3
-1
3.041
10
6.2
-42
2
-3
-3
2.333
Infinity
-Infinity
NaN
1
2
-2