SHARE
TWEET

Untitled

a guest Jun 17th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.List;
  7. import java.util.Scanner;
  8. import java.util.stream.Collector;
  9. import java.util.stream.Collectors;
  10.  
  11. public class Main {
  12.  
  13.     public static void main(String[] args) {
  14.         Scanner scanner = new Scanner(System.in);
  15.  
  16.         List<Integer> firstHand = Arrays.stream(scanner.nextLine().split(" "))
  17.                 .map(Integer :: parseInt)
  18.                 .collect(Collectors.toList());
  19.         List<Integer> secondHand = Arrays.stream(scanner.nextLine().split(" "))
  20.                 .map(Integer :: parseInt)
  21.                 .collect(Collectors.toList());
  22.  
  23.         List<Integer> newFirst = new ArrayList<>();
  24.         List<Integer> newSecond = new ArrayList<>();
  25.  
  26.         int topSum = 0;
  27.         int bottomSum = 0;
  28.  
  29.         for (int i = 0; i < firstHand.size() ; i++) {
  30.  
  31.             if(firstHand.get(i) > secondHand.get(i)){
  32.                 newFirst.add(firstHand.get(i));
  33.                 newFirst.add(secondHand.get(i));
  34.                 if (newSecond.size() > 0){
  35.                     bottomSum -= secondHand.get(i);
  36.                 }
  37.             }else if (secondHand.get(i) > firstHand.get(i)){
  38.                 newSecond.add(secondHand.get(i));
  39.                 newSecond.add(firstHand.get(i));
  40.                 if (newFirst.size() > 0){
  41.                     topSum -= firstHand.get(i);
  42.                 }
  43.             }
  44.         }
  45.         for (int i = 0; i < newFirst.size(); i++) {
  46.             topSum += newFirst.get(i);
  47.         }
  48.         for (int i = 0; i < newSecond.size(); i++) {
  49.             bottomSum += newSecond.get(i);
  50.         }
  51.         if (topSum > bottomSum){
  52.             System.out.println("First player wins! Sum: " + topSum);
  53.         }else{
  54.             System.out.println("Second player wins! Sum: " + bottomSum);
  55.         }
  56.     }
  57. }
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