Exercise 1. Train - Lists Exercise
Здравейте,
имам нужда от помощ за тази задача. Нещо не мога да хвана в цикъла какво се иска от мен. Ще се радвам за примерно решение!
Условие:
1.Train
You will receive a list of wagons (integers) on the first line. Every integer represents the number of passengers that are currently in each of the wagons. On the next line, you will get the max capacity of each wagon (a single integer). Until you receive "end" you will be given two types of input:
- Add {passengers} – add a wagon to the end with the given number of passengers.
- {passengers} - find an existing wagon to fit every passenger, starting from the first wagon.
At the end print the final state of the train (each of the wagons, separated by a space).
Example
Input |
Output |
32 54 21 12 4 0 23 75 Add 10 Add 0 30 10 75 end |
72 54 21 12 4 75 23 10 0 |
0 0 0 10 2 4 10 Add 10 10 10 10 8 6 end |
10 10 10 10 10 10 10 |