結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー htensaihtensai
提出日時 2019-12-06 10:53:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,266 bytes
コンパイル時間 5,440 ms
コンパイル使用メモリ 79,604 KB
実行使用メモリ 58,876 KB
最終ジャッジ日時 2023-08-24 19:47:56
合計ジャッジ時間 8,366 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 158 ms
56,612 KB
testcase_01 AC 158 ms
56,856 KB
testcase_02 AC 157 ms
57,040 KB
testcase_03 WA -
testcase_04 AC 165 ms
56,744 KB
testcase_05 AC 164 ms
56,804 KB
testcase_06 AC 166 ms
56,764 KB
testcase_07 AC 163 ms
56,972 KB
testcase_08 AC 164 ms
56,884 KB
testcase_09 AC 167 ms
56,776 KB
testcase_10 AC 125 ms
56,288 KB
testcase_11 AC 160 ms
56,820 KB
testcase_12 AC 159 ms
57,092 KB
testcase_13 AC 157 ms
56,688 KB
testcase_14 AC 154 ms
57,064 KB
testcase_15 AC 162 ms
56,984 KB
testcase_16 AC 159 ms
57,060 KB
testcase_17 WA -
testcase_18 AC 164 ms
57,220 KB
testcase_19 AC 163 ms
56,624 KB
testcase_20 AC 158 ms
56,628 KB
testcase_21 AC 159 ms
56,588 KB
testcase_22 AC 160 ms
56,828 KB
testcase_23 WA -
testcase_24 AC 162 ms
57,056 KB
testcase_25 AC 156 ms
56,896 KB
testcase_26 AC 159 ms
56,768 KB
testcase_27 AC 126 ms
56,244 KB
testcase_28 AC 156 ms
56,484 KB
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." + String.format("%010d", right * -1));
		        return;
		    }
		}
		System.out.println(left + "." + String.format("%010d", right));
   }
}

0