結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー yuruhiyayuruhiya
提出日時 2020-04-29 22:07:09
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 509 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 11,256 KB
実行使用メモリ 15,420 KB
最終ジャッジ日時 2023-08-20 02:47:18
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,132 KB
testcase_01 AC 85 ms
15,044 KB
testcase_02 AC 84 ms
15,052 KB
testcase_03 AC 82 ms
15,152 KB
testcase_04 AC 84 ms
15,280 KB
testcase_05 AC 85 ms
15,344 KB
testcase_06 AC 84 ms
15,176 KB
testcase_07 AC 85 ms
15,356 KB
testcase_08 AC 83 ms
15,164 KB
testcase_09 AC 82 ms
15,188 KB
testcase_10 WA -
testcase_11 AC 79 ms
15,184 KB
testcase_12 AC 80 ms
15,188 KB
testcase_13 AC 79 ms
15,048 KB
testcase_14 AC 80 ms
15,100 KB
testcase_15 AC 81 ms
15,180 KB
testcase_16 AC 80 ms
15,160 KB
testcase_17 WA -
testcase_18 AC 80 ms
15,304 KB
testcase_19 AC 79 ms
15,308 KB
testcase_20 AC 79 ms
15,176 KB
testcase_21 AC 81 ms
15,316 KB
testcase_22 AC 80 ms
15,180 KB
testcase_23 AC 82 ms
15,328 KB
testcase_24 AC 83 ms
15,252 KB
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 82 ms
15,176 KB
testcase_29 AC 80 ms
15,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

ans = 0
gets.to_i.times do |i|
    s = gets.chomp
    neg = false
    num = 0
    if s[0] == '-'
        neg = true
        s = s[1...s.size]
    end

    if s.include?('.')
        pos = s.index('.')
        a = s[0...pos]
        b = s[pos + 1...s.size]
        b += "0" * (10 - b.size)
        num = a.to_i * (10 ** 10) + b.to_i
    else
        num = s.to_i * (10 ** 10)
    end

    if neg
        ans -= num
    else
        ans += num
    end
end

ans = ans.to_s
ans.insert(ans.size - 10, '.')
puts ans
0