結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー htensai
提出日時 2019-12-06 09:31:21
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,218 bytes
コンパイル時間 2,883 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 55,088 KB
最終ジャッジ日時 2024-12-23 05:01:22
合計ジャッジ時間 8,456 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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