結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー tentententen
提出日時 2023-07-07 08:44:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,605 bytes
コンパイル時間 4,332 ms
コンパイル使用メモリ 81,740 KB
実行使用メモリ 53,988 KB
最終ジャッジ日時 2023-09-28 08:59:57
合計ジャッジ時間 8,028 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 66 ms
50,788 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 65 ms
51,728 KB
testcase_06 WA -
testcase_07 AC 64 ms
51,932 KB
testcase_08 AC 64 ms
50,684 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 69 ms
51,392 KB
testcase_16 AC 66 ms
51,640 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 64 ms
52,280 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long big = 0;
        long small = 0;
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int idx = s.indexOf(".");
            if (idx < 0) {
                big += Long.parseLong(s);
            } else {
                if (s.charAt(0) == '-') {
                    big -= Long.parseLong(s.substring(1, idx));
                    int length = s.length() - idx;
                    small -= Long.parseLong(s.substring(idx + 1, s.length())) * pow(10, 10 - length + 1);
                } else {
                    big += Long.parseLong(s.substring(0, idx));
                    int length = s.length() - idx;
                    small += Long.parseLong(s.substring(idx + 1, s.length())) * pow(10, 10 - length + 1);
                }
            }
        }
        while (small < 0) {
            big--;
            small += 10000000000L;
        }
        big += small / 10000000000L;
        small %= 10000000000L;
        System.out.println(big + "." + small);
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else {
            return pow(x, p - 1) * x;
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0