結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー GrenacheGrenache
提出日時 2016-12-28 12:31:00
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,650 bytes
コンパイル時間 4,908 ms
コンパイル使用メモリ 79,392 KB
実行使用メモリ 41,604 KB
最終ジャッジ日時 2024-04-21 11:45:34
合計ジャッジ時間 9,774 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,240 KB
testcase_01 AC 115 ms
40,636 KB
testcase_02 AC 126 ms
41,328 KB
testcase_03 AC 114 ms
41,208 KB
testcase_04 AC 138 ms
41,240 KB
testcase_05 AC 119 ms
40,584 KB
testcase_06 AC 127 ms
40,980 KB
testcase_07 AC 134 ms
41,240 KB
testcase_08 AC 128 ms
41,404 KB
testcase_09 AC 130 ms
41,296 KB
testcase_10 AC 116 ms
40,512 KB
testcase_11 AC 137 ms
41,236 KB
testcase_12 AC 116 ms
40,288 KB
testcase_13 AC 121 ms
41,100 KB
testcase_14 AC 124 ms
41,260 KB
testcase_15 AC 130 ms
41,396 KB
testcase_16 AC 123 ms
41,308 KB
testcase_17 WA -
testcase_18 AC 154 ms
41,532 KB
testcase_19 AC 140 ms
41,124 KB
testcase_20 AC 125 ms
40,864 KB
testcase_21 AC 116 ms
40,160 KB
testcase_22 AC 136 ms
41,372 KB
testcase_23 AC 138 ms
41,544 KB
testcase_24 AC 132 ms
41,128 KB
testcase_25 AC 117 ms
41,232 KB
testcase_26 AC 118 ms
40,120 KB
testcase_27 AC 110 ms
39,952 KB
testcase_28 AC 128 ms
41,212 KB
testcase_29 AC 132 ms
41,272 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)) {
            System.out.printf("%d.%010d\n", intp, decimal);
        } else if (intp < 0 && decimal < 0) {
            System.out.printf("%d.%010d\n", intp, Math.abs(decimal));
        } else if (intp == 0 && decimal < 0) {
            System.out.printf("-%d.%010d\n", intp, Math.abs(decimal));
        } else if (intp > 0 && decimal < 0) {
        	intp--;
            decimal += 10000000000L;
            System.out.printf("%d.%010d\n", intp, decimal);
        } else if (intp < 0 && decimal > 0) {
        	intp++;
            decimal = 10000000000L - decimal;
            System.out.printf("%d.%010d\n", intp, decimal);
        } else if (intp < 0 && decimal == 0) {
            System.out.printf("%d.%010d\n", intp, decimal);
        }

        sc.close();
    }
}
0