Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Stream;
  8.  
  9. public class etakadaima {
  10. public static void main(String[] args) {
  11.  
  12. Scanner scanner = new Scanner(System.in);
  13.  
  14. ArrayList<Integer> train = new ArrayList<>();
  15.  
  16. String[] InputData = scanner.nextLine().split(" +");
  17.  
  18.  
  19. for (int i = 0; i < InputData.length; i++) {
  20. train.add(Integer.parseInt(InputData[i]));
  21. }
  22.  
  23.  
  24. int Capacity = Integer.parseInt(scanner.nextLine());
  25.  
  26. String command = scanner.nextLine();
  27. while (!command.equals("end")){
  28. String [] massiveOfCommand = command.split(" ");
  29.  
  30. if (command.contains("Add")){
  31. int people = Integer.parseInt(massiveOfCommand[1]);
  32. train.add(people);
  33. }else {
  34. int people = Integer.parseInt(massiveOfCommand[0]);
  35.  
  36. for (int i = 0; i < train.size() ; i++) {
  37. int currentPeople =people + train.get(i);
  38. if (currentPeople<= Capacity){
  39. train.set(i,currentPeople );
  40. break;
  41. }
  42.  
  43. }
  44. }
  45.  
  46.  
  47.  
  48.  
  49. command= scanner.nextLine();
  50.  
  51. }
  52.  
  53.  
  54. for (int i = 0; i < train.size() ; i++) {
  55. System.out.print(train.get(i) + " ");
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement