結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー GrenacheGrenache
提出日時 2015-11-06 20:55:20
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 3,482 ms
コンパイル使用メモリ 76,628 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-10-11 14:24:49
合計ジャッジ時間 9,038 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,808 KB
testcase_01 AC 130 ms
55,524 KB
testcase_02 AC 130 ms
55,472 KB
testcase_03 AC 125 ms
55,872 KB
testcase_04 AC 144 ms
55,820 KB
testcase_05 AC 135 ms
55,848 KB
testcase_06 AC 138 ms
56,276 KB
testcase_07 AC 137 ms
54,044 KB
testcase_08 AC 137 ms
56,368 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 144 ms
55,980 KB
testcase_16 AC 131 ms
56,032 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 142 ms
55,716 KB
testcase_24 WA -
testcase_25 AC 126 ms
56,112 KB
testcase_26 AC 128 ms
55,984 KB
testcase_27 WA -
testcase_28 AC 130 ms
56,044 KB
testcase_29 AC 139 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder81 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        long decimal = 0;
        long intp = 0;
        for (int i = 0; i < n; i++) {
        	String a = sc.next();

        	int index = a.indexOf('.');
        	if (index == -1) {
        		intp += Long.parseLong(a);
        	} else {
                long sign = 1;
        		if (a.charAt(0) == '-') {
        			sign = -1;
        		}
        		intp += Long.parseLong(a.substring(0, index));
        		String tmp = a.substring(index + 1);
        		while (tmp.length() < 10) {
        			tmp += "0";
        		}
        		decimal += sign * Long.parseLong(tmp);
        	}
        }

    	intp += decimal / 10000000000L;
    	decimal %= 10000000000L;
        if ((intp >= 0 && decimal >= 0) || (intp < 0 && decimal < 0)) {
        } else if (intp >= 0 && decimal < 0) {
        	intp--;
            decimal += 10000000000L;
            decimal %= 10000000000L;
        } else if (intp < 0 && decimal >= 0) {
        	intp++;
            decimal = 10000000000L - decimal;
            decimal %= 10000000000L;
        }

        System.out.printf("%d.%010d\n", intp, decimal);

        sc.close();
    }
}
0