Untitled

mail@pastecode.io avatar
unknown
plain_text
14 days ago
2.0 kB
0
Indexable
Never
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

class Result {

    /*
     * Complete the 'plusMinus' function below.
     *
     * The function accepts INTEGER_ARRAY arr as parameter.
     */

    public static void plusMinus(List<Integer> arr) {
    // Write your code here
        int pos=0;
        int neg=0;
        int zero=0;
        for (int i=0; i<arr.size(); i++ ) {
            //positive
            if (arr.get(i)>0) {
                pos++;
            }
            //negative
            if (arr.get(i)<0) {
                neg++;
            }
            //zeros
            if (arr.get(i)==0) {
                zero++;
            }
        }   
            double posRatio = (double) pos/arr.size();
            double negRatio = (double) neg/arr.size();
            double zeroRatio = (double) zero/arr.size();
            System.out.format("%.6f ", posRatio);
            System.out.println("");
            System.out.format("%.6f ", negRatio);
            System.out.println("");
            System.out.format("%.6f ", zeroRatio);
            //System.out.println(posRatio);
            //System.out.println(negRatio);
            //System.out.println(zeroRatio);
    }
}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        int n = Integer.parseInt(bufferedReader.readLine().trim());

        List<Integer> arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
            .map(Integer::parseInt)
            .collect(toList());

        Result.plusMinus(arr);

        bufferedReader.close();
    }
}
Leave a Comment