結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー tentententen
提出日時 2020-11-18 17:30:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,960 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 75,856 KB
実行使用メモリ 56,284 KB
最終ジャッジ日時 2023-09-30 15:07:37
合計ジャッジ時間 7,982 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
56,108 KB
testcase_01 AC 148 ms
56,096 KB
testcase_02 AC 148 ms
55,820 KB
testcase_03 AC 147 ms
55,904 KB
testcase_04 AC 153 ms
55,820 KB
testcase_05 AC 149 ms
56,040 KB
testcase_06 AC 152 ms
55,816 KB
testcase_07 AC 152 ms
55,904 KB
testcase_08 AC 152 ms
55,768 KB
testcase_09 AC 154 ms
55,864 KB
testcase_10 WA -
testcase_11 AC 148 ms
55,980 KB
testcase_12 AC 149 ms
55,996 KB
testcase_13 AC 145 ms
55,600 KB
testcase_14 AC 145 ms
55,908 KB
testcase_15 AC 153 ms
55,984 KB
testcase_16 AC 148 ms
55,856 KB
testcase_17 WA -
testcase_18 AC 154 ms
55,892 KB
testcase_19 AC 149 ms
56,112 KB
testcase_20 AC 145 ms
55,816 KB
testcase_21 AC 144 ms
56,136 KB
testcase_22 AC 148 ms
55,908 KB
testcase_23 AC 155 ms
55,792 KB
testcase_24 AC 151 ms
55,744 KB
testcase_25 AC 145 ms
55,592 KB
testcase_26 AC 145 ms
55,928 KB
testcase_27 WA -
testcase_28 AC 143 ms
54,416 KB
testcase_29 AC 148 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long big = 0;
        long small = 0;
        for (int i = 0; i < n; i++) {
            char[] arr = sc.next().toCharArray();
            long x = 0;
            long y = 0;
            int count = 0;
            boolean isPlus = true;
            boolean hasDot = false;
            for (int j = 0; j < arr.length || (hasDot && count < 10); j++) {
                if (!hasDot && arr[j] == '-') {
                    isPlus = false;
                } else if (!hasDot && arr[j] == '.') {
                    hasDot = true;
                } else {
                    if (!hasDot) {
                        x *= 10;
                        x += arr[j] - '0';
                    } else {
                        y *= 10;
                        count++;
                        if (j < arr.length) {
                            y += arr[j] - '0';
                        }
                    }
                }
            }
            if (isPlus) {
                big += x;
                small += y;
            } else {
                big -= x;
                small -= y;
            }
        }
        if (small <= -10000000000L) {
            big += small / 10000000000L;
            small = -(-small % 10000000000L); 
        } else if (small >= 10000000000L) {
            big += small / 10000000000L;
            small %= 10000000000L;
        }
        if (small < 0) {
            if (big >= 0) {
                big--;
                small = 10000000000L + small;
            } else {
                small = -small;
            }
        } else {
            if (big < 0 && small != 0) {
                big++;
                small = 10000000000L - small;
            }
        }
        System.out.print(big + ".");
        System.out.printf("%010d\n", small);
    }
}
0