Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01Train
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> wagons = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- int maxCapacityOfEachWagon = int.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- while (command != "end")
- {
- List<string> directions = command.Split().ToList();
- if (directions[0] == "Add")
- {
- int custemersInWagon = int.Parse(directions[1]);
- wagons.Add(custemersInWagon);
- }
- else
- {
- int passangerToFit = int.Parse(directions[0]);
- for (int i = 0; i < wagons.Count; i++)
- {
- if (wagons[i] + passangerToFit <= maxCapacityOfEachWagon)
- {
- wagons[i] += passangerToFit;
- break;
- }
- }
- }
- }
- Console.WriteLine(string.Join(" ", wagons));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement