結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,256 KB
testcase_01 AC 76 ms
15,252 KB
testcase_02 AC 78 ms
15,136 KB
testcase_03 AC 78 ms
15,132 KB
testcase_04 AC 79 ms
15,000 KB
testcase_05 AC 77 ms
15,264 KB
testcase_06 AC 76 ms
15,092 KB
testcase_07 AC 77 ms
15,236 KB
testcase_08 AC 78 ms
15,132 KB
testcase_09 AC 78 ms
15,132 KB
testcase_10 WA -
testcase_11 AC 78 ms
15,260 KB
testcase_12 AC 78 ms
15,176 KB
testcase_13 AC 78 ms
15,092 KB
testcase_14 AC 77 ms
15,084 KB
testcase_15 AC 79 ms
15,104 KB
testcase_16 AC 76 ms
15,296 KB
testcase_17 AC 77 ms
15,048 KB
testcase_18 AC 78 ms
15,140 KB
testcase_19 AC 77 ms
15,116 KB
testcase_20 AC 77 ms
15,256 KB
testcase_21 AC 77 ms
15,276 KB
testcase_22 AC 77 ms
14,996 KB
testcase_23 AC 78 ms
15,088 KB
testcase_24 AC 77 ms
15,264 KB
testcase_25 RE -
testcase_26 AC 77 ms
15,128 KB
testcase_27 AC 76 ms
15,084 KB
testcase_28 AC 76 ms
15,096 KB
testcase_29 AC 77 ms
15,004 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
if ans.chars.count {|c| c != '-' } == 10
    ans.insert(ans[0] == '-' ? 1 : 0, '0')
end
ans.insert(ans.size - 10, '.')
puts ans
0