SHARE
TWEET

Untitled

a guest Oct 18th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.regex.*;
  8.  
  9. import java.util.function.IntConsumer;
  10. import java.util.stream.IntStream;
  11.  
  12. public class Solution {
  13.  
  14.     // Complete the plusMinus function below.
  15.     static void plusMinus(int[] arr) {
  16.         IntStream.of(arr).collect(DangStatisTic::new, DangStatisTic::accept, (a, b) -> {
  17.         throw new UnsupportedOperationException();
  18.         }).print();
  19.  
  20.     }
  21.  
  22.     private static final Scanner scanner = new Scanner(System.in);
  23.  
  24.     public static void main(String[] args) {
  25.         int n = scanner.nextInt();
  26.         scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
  27.  
  28.         int[] arr = new int[n];
  29.  
  30.         String[] arrItems = scanner.nextLine().split(" ");
  31.         scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
  32.  
  33.         for (int i = 0; i < n; i++) {
  34.             int arrItem = Integer.parseInt(arrItems[i]);
  35.             arr[i] = arrItem;
  36.         }
  37.  
  38.         plusMinus(arr);
  39.  
  40.         scanner.close();
  41.     }
  42. }
  43. class DangStatisTic implements IntConsumer {
  44.  
  45.   int biggerThan0;
  46.  
  47.   int lessThan0;
  48.  
  49.   int is0;
  50.  
  51.   int size;
  52.  
  53.   public DangStatisTic() {}
  54.  
  55.   public void print() {
  56.     System.out.println(String.format("%.6f", (float) biggerThan0 / ((float) size)));
  57.     System.out.println(String.format("%.6f", (float) lessThan0 / ((float) size)));
  58.     System.out.println(String.format("%.6f", (float) is0 / ((float) size)));
  59.  
  60.   }
  61.  
  62.   @Override
  63.   public void accept(int value) {
  64.     if (value > 0) biggerThan0++;
  65.     if (value < 0) lessThan0++;
  66.     if (value == 0) is0++;
  67.     size++;
  68.   }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top