結果
問題 | No.49 算数の宿題 |
ユーザー |
|
提出日時 | 2016-08-18 10:47:26 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 100 ms / 5,000 ms |
コード長 | 639 bytes |
コンパイル時間 | 54 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-12-23 01:53:17 |
合計ジャッジ時間 | 1,682 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
コンパイルメッセージ
Syntax OK
ソースコード
class Calc0049 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @s = args.shift.first end def run stack = [] @s.scan(/\d+|[+*]/).each do |t| case t when /\d+/ t = t.to_i if stack.empty? stack.push(t) else op = stack.pop target = stack.pop case op when '+' stack.push(target * t) when '*' stack.push(target + t) end end when '+', '*' stack.push(t) end end stack.pop end end puts Calc0049.new(STDIN.readlines).run if __FILE__ == $0