結果

問題 No.49 算数の宿題
ユーザー 👑 yumechiyumechi
提出日時 2015-11-30 21:07:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 853 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 11,440 KB
実行使用メモリ 15,320 KB
最終ジャッジ日時 2023-08-24 17:27:17
合計ジャッジ時間 1,557 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,260 KB
testcase_01 AC 76 ms
15,232 KB
testcase_02 AC 77 ms
15,228 KB
testcase_03 AC 78 ms
15,320 KB
testcase_04 AC 77 ms
15,152 KB
testcase_05 AC 77 ms
15,176 KB
testcase_06 AC 82 ms
15,156 KB
testcase_07 AC 77 ms
15,156 KB
testcase_08 AC 77 ms
15,144 KB
testcase_09 AC 77 ms
15,080 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

s = gets.chomp
first, second = 0, 0
lastmark = ""
flag = false
for c in s.split(//) do
    if c == "*"
        if flag
            if lastmark == "*"
                first = first + second
            else
                first = first * second
            end
            second = 0
        else
            flag = true
        end
        lastmark = c
    elsif c == "+"
        if flag
            if lastmark == "*"
                first = first + second
            else
                first = first * second
            end
            second = 0
        else
            flag = true
        end
        lastmark = c
    else
        if flag
            second *= 10
            second += c.to_i
        else
            first *= 10
            first += c.to_i
        end
    end
end
puts (lastmark == "*") ? (first + second) : (first * second)
0