Advertisement
Daniel_007

01. Train

Feb 20th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp5
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> passengers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             int maxCapacity = int.Parse(Console.ReadLine());
  13.             while (true)
  14.             {
  15.                 string[] input = Console.ReadLine().Split().ToArray();
  16.                 if (input[0] == "end")
  17.                 {
  18.                     Console.WriteLine(string.Join(" ", passengers));
  19.                     return;
  20.                 }
  21.                 else if (input[0] == "Add")
  22.                 {
  23.                     passengers.Add(int.Parse(input[1]));
  24.                 }
  25.                 else
  26.                 {
  27.                     for (int i = 0; i < passengers.Count; i++)
  28.                     {
  29.                         if (passengers[i] + int.Parse(input[0]) <= maxCapacity)
  30.                         {
  31.                             int temp = passengers[i];
  32.                             passengers.Insert(i, int.Parse(input[0])+temp);
  33.                             passengers.RemoveAt(i + 1);
  34.                             break;
  35.                         }
  36.                     }
  37.                 }
  38.             }
  39.  
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement