ia-toki / tlx

Pusat Pelaporan Isu TLX Training Gate
18 stars 2 forks source link

Question : [Soal Tambahan] Rata-Rata #35

Closed DevilLord41 closed 5 years ago

DevilLord41 commented 6 years ago

Soal : [Versi Lama] Training Gate -> Struktur Data -> Soal Tambahan -> E. Rata-Rata Case : Wrong answer, padahal sudah dipastikan benar, tidak ada spasi tambahan ataupun linebreak tambahan.

Code :

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int J = sc.nextInt();
        ArrayList<Double> a = new ArrayList<Double>();
        for(int i = 0; i < J;i++) {
            a.add(sc.nextDouble());
        }
        DecimalFormat df = new DecimalFormat("#.00");
        System.out.print(df.format(Collections.min(a)) + " " + df.format(Collections.max(a)) + " " + df.format(a.stream().mapToDouble(v->v).sum()/J));
        sc.close();
    }
}
fushar commented 5 years ago

Mohon ditanyakan pada https://www.facebook.com/groups/olimpinfo/.