結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー Grenache
提出日時 2015-11-06 21:00:22
言語 Java
(openjdk 23)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,216 bytes
コンパイル時間 4,286 ms
コンパイル使用メモリ 79,576 KB
実行使用メモリ 41,684 KB
最終ジャッジ日時 2024-12-15 00:40:22
合計ジャッジ時間 9,757 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 11
権限があれば一括ダウンロードができます

ソースコード

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) || (intp < 0 && decimal < 0)) {
        } else if (intp >= 0 && decimal < 0) {
        	intp--;
            decimal += 10000000000L;
        } else if (intp < 0 && decimal > 0) {
        	intp++;
            decimal = 10000000000L - decimal;
        }

        System.out.printf("%d.%010d\n", intp, decimal);

        sc.close();
    }
}
0