Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.lang.reflect.Array;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Stream;
- public class etakadaima {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<Integer> train = new ArrayList<>();
- String[] InputData = scanner.nextLine().split(" +");
- for (int i = 0; i < InputData.length; i++) {
- train.add(Integer.parseInt(InputData[i]));
- }
- int Capacity = Integer.parseInt(scanner.nextLine());
- String command = scanner.nextLine();
- while (!command.equals("end")){
- String [] massiveOfCommand = command.split(" ");
- if (command.contains("Add")){
- int people = Integer.parseInt(massiveOfCommand[1]);
- train.add(people);
- }else {
- int people = Integer.parseInt(massiveOfCommand[0]);
- for (int i = 0; i < train.size() ; i++) {
- int currentPeople =people + train.get(i);
- if (currentPeople<= Capacity){
- train.set(i,currentPeople );
- break;
- }
- }
- }
- command= scanner.nextLine();
- }
- for (int i = 0; i < train.size() ; i++) {
- System.out.print(train.get(i) + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement