結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-02 03:37:06
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,433 bytes
コンパイル時間 3,602 ms
コンパイル使用メモリ 75,488 KB
実行使用メモリ 61,068 KB
最終ジャッジ日時 2023-08-18 12:08:08
合計ジャッジ時間 8,810 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
56,728 KB
testcase_01 AC 146 ms
56,776 KB
testcase_02 AC 148 ms
56,480 KB
testcase_03 WA -
testcase_04 AC 152 ms
56,692 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 149 ms
56,784 KB
testcase_12 AC 154 ms
56,720 KB
testcase_13 AC 148 ms
56,688 KB
testcase_14 AC 150 ms
56,892 KB
testcase_15 AC 152 ms
57,156 KB
testcase_16 AC 147 ms
56,792 KB
testcase_17 AC 144 ms
56,828 KB
testcase_18 WA -
testcase_19 AC 153 ms
56,768 KB
testcase_20 AC 146 ms
56,632 KB
testcase_21 AC 143 ms
56,660 KB
testcase_22 AC 149 ms
56,884 KB
testcase_23 WA -
testcase_24 AC 150 ms
56,572 KB
testcase_25 WA -
testcase_26 AC 141 ms
56,688 KB
testcase_27 AC 143 ms
56,828 KB
testcase_28 AC 147 ms
56,920 KB
testcase_29 AC 152 ms
56,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long sum=0;
        for(int i=0; i<N; i++){
            String S = sc.next();
            sum+=inde(S);
        }
        long m=1000000000L;
        if(sum>0){
            String integer=String.valueOf(sum/m);
            String decimal=String.valueOf(sum%m);
            while(decimal.length()<10){
                decimal+="0";
            }
            System.out.println(integer+"."+decimal);
        }else{
            sum*=-1;
            String integer=String.valueOf(sum/m);
            String decimal=String.valueOf(sum%m);
            while(decimal.length()<10){
                decimal+="0";
            }
            System.out.println("-"+integer+"."+decimal);        
        }
    }
    static long inde(String S){
        long m=1000000000L;
        int t = S.indexOf(".");
        long x;
        if(t==-1){
            x=Long.parseLong(S)*m;
        }else{
            String S1=S.substring(0,t);
            String S2=S.substring(t+1);
            while(S2.length()<9){
                S2=S2+"0";
            }
            long x1=Long.parseLong(S1)*m;
            long x2=Long.parseLong(S2);
            if(S.contains("-")){
                x=x1-x2;
            }else{
                x=x1+x2;
            }
        }
        return x;
    }
}
0