Advertisement
Spocoman

01. Train

Feb 1st, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Train
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> wagoons = Console.ReadLine()
  12.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToList();
  15.  
  16.             int capacity = int.Parse(Console.ReadLine());
  17.             string[] command = Console.ReadLine()
  18.                 .ToLower()
  19.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  20.                 .ToArray();
  21.                
  22.             while (command[0] != "end")
  23.             {
  24.                 if (command.Length == 2)
  25.                 {
  26.                     switch (command[0])
  27.                     {
  28.                         case "add":
  29.                             wagoons.Add(wagoons.Count + 1);
  30.                             wagoons[wagoons.Count - 1] = int.Parse(command[1]);
  31.                             break;
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     for (int i = 0; i < wagoons.Count; i++)
  37.                     {
  38.                         int sum = wagoons[i] + int.Parse(command[0]);
  39.  
  40.                         if (sum <= capacity)
  41.                         {
  42.                             wagoons[i] = sum;
  43.                             break;
  44.                         }
  45.                     }
  46.                 }
  47.                 command = Console.ReadLine()
  48.                    .ToLower()
  49.                    .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  50.                    .ToArray();
  51.             }
  52.             Console.WriteLine(string.Join(" ", wagoons));
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement