Advertisement
Andreeva-Magdalena97

Party

Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package EX1702;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class ClubParty {
  7.     public static void main(String[] args) {
  8.         Scanner s = new Scanner(System.in);
  9.         int n = Integer.parseInt(s.nextLine());
  10.         String[]list = s.nextLine().split(" ");
  11.         ArrayDeque<String> op = new ArrayDeque<>();
  12.         List<Integer> lists = new ArrayList<>();
  13.         int count = 0;
  14.         for (int i = list.length - 1; i >= 0 ; i--) {
  15.             String element = list[i];
  16.             if (Character.isAlphabetic(element.charAt(0))){
  17.                 op.offer(element);
  18.             }else {
  19.                 if (op.isEmpty()){
  20.                     continue;
  21.                 }
  22.                 int number = Integer.parseInt(element);
  23.                 count = lists.stream().mapToInt(x-> x).sum();
  24.                 if (count + number <= n){
  25.                     lists.add(number);
  26.                 }else {
  27.                     System.out.print(op.poll());
  28.                     System.out.print(" -> ");
  29.                     System.out.println(String.join(", ", lists.stream().map(String::valueOf).collect(Collectors.toList())));
  30.                     lists.clear();
  31.                    i++;
  32.                         }
  33.                     }
  34.  
  35.                 }
  36.             }
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement