結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー GrenacheGrenache
提出日時 2018-09-16 16:50:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 1,729 bytes
コンパイル時間 4,491 ms
コンパイル使用メモリ 80,048 KB
実行使用メモリ 46,360 KB
最終ジャッジ日時 2023-09-29 22:44:14
合計ジャッジ時間 10,964 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
39,360 KB
testcase_01 AC 116 ms
39,572 KB
testcase_02 AC 121 ms
39,760 KB
testcase_03 AC 112 ms
38,956 KB
testcase_04 AC 137 ms
39,292 KB
testcase_05 AC 116 ms
39,672 KB
testcase_06 AC 119 ms
39,328 KB
testcase_07 AC 119 ms
39,612 KB
testcase_08 AC 128 ms
39,756 KB
testcase_09 AC 122 ms
39,396 KB
testcase_10 AC 133 ms
38,988 KB
testcase_11 AC 142 ms
39,232 KB
testcase_12 AC 143 ms
39,756 KB
testcase_13 AC 134 ms
39,124 KB
testcase_14 AC 132 ms
39,364 KB
testcase_15 AC 147 ms
39,476 KB
testcase_16 AC 132 ms
39,296 KB
testcase_17 AC 133 ms
39,800 KB
testcase_18 AC 143 ms
39,220 KB
testcase_19 AC 145 ms
39,536 KB
testcase_20 AC 137 ms
39,228 KB
testcase_21 AC 135 ms
39,120 KB
testcase_22 AC 143 ms
39,104 KB
testcase_23 AC 158 ms
39,400 KB
testcase_24 AC 142 ms
39,152 KB
testcase_25 AC 120 ms
46,360 KB
testcase_26 AC 109 ms
39,604 KB
testcase_27 AC 109 ms
39,372 KB
testcase_28 AC 113 ms
39,504 KB
testcase_29 AC 122 ms
39,280 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;
            if (intp == 0) {
            	System.out.print('-');
            }
            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