Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Train
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> wagoons = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- int capacity = int.Parse(Console.ReadLine());
- string[] command = Console.ReadLine()
- .ToLower()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- while (command[0] != "end")
- {
- if (command.Length == 2)
- {
- switch (command[0])
- {
- case "add":
- wagoons.Add(wagoons.Count + 1);
- wagoons[wagoons.Count - 1] = int.Parse(command[1]);
- break;
- }
- }
- else
- {
- for (int i = 0; i < wagoons.Count; i++)
- {
- int sum = wagoons[i] + int.Parse(command[0]);
- if (sum <= capacity)
- {
- wagoons[i] = sum;
- break;
- }
- }
- }
- command = Console.ReadLine()
- .ToLower()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- }
- Console.WriteLine(string.Join(" ", wagoons));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement