結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー htensaihtensai
提出日時 2019-12-06 09:31:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 3,351 ms
コンパイル使用メモリ 78,744 KB
実行使用メモリ 59,040 KB
最終ジャッジ日時 2023-08-24 19:45:58
合計ジャッジ時間 9,816 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 155 ms
56,784 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 155 ms
56,640 KB
testcase_06 WA -
testcase_07 AC 158 ms
56,480 KB
testcase_08 AC 160 ms
56,680 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 155 ms
56,824 KB
testcase_12 AC 156 ms
56,744 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 161 ms
56,776 KB
testcase_16 AC 150 ms
56,708 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 158 ms
56,940 KB
testcase_20 AC 154 ms
56,520 KB
testcase_21 AC 153 ms
56,676 KB
testcase_22 AC 154 ms
56,552 KB
testcase_23 WA -
testcase_24 AC 160 ms
56,892 KB
testcase_25 WA -
testcase_26 AC 153 ms
56,724 KB
testcase_27 AC 139 ms
55,612 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long left = 0;
		long right = 0;
		for (int i = 0; i < n; i++) {
		    String str = sc.next();
		    if (str.contains(".")) {
		        String leftString = str.substring(0, str.indexOf("."));
		        left += Long.parseLong(leftString);
		        String rightString = str.substring(str.indexOf(".") + 1, str.length());
		        char[] arr = new char[10];
		        Arrays.fill(arr, '0');
		        for (int j = 0; j < rightString.length(); j++) {
		            arr[j] = rightString.charAt(j);
		        }
		        long x = Long.parseLong(new String(arr));
		        if (str.charAt(0) == '-') {
		            x *= -1;
		        }
		        right += x;
		    } else {
		        left += Long.parseLong(str);
		    }
		}
		left += right / 10000000000L;
		right %= 10000000000L;
		
		if (right < 0) {
		    if (left > 0) {
		        left--;
		        right += 10000000000L;
		    } else if (left < 0) {
		        right *= -1;
		    } else {
		        System.out.println("-0." + right * -1);
		        return;
		    }
		}
		System.out.println(left + "." + right);
   }
}

0