Guest User

Untitled

a guest
Feb 14th, 2020
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _1._Train
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> passengers = Console
  12. .ReadLine()
  13. .Split()
  14. .Select(int.Parse)
  15. .ToList();
  16.  
  17. int countOfList = passengers.Count;
  18. int maxCapacity = int.Parse(Console.ReadLine());
  19.  
  20. while (true)
  21. {
  22. string command = Console.ReadLine();
  23. if(command == "end")
  24. {
  25. break;
  26. }
  27. string[] token = command.Split();
  28. if(token[0] == "Add")
  29. {
  30. int passengerToAdd = int.Parse(token[1]);
  31. passengers.Add(passengerToAdd);
  32. }
  33. else
  34. {
  35. int passengerToFit = int.Parse(token[0]);
  36. for (int i = 0; i < countOfList; i++)
  37. {
  38. if((passengers[i] + passengerToFit) <= maxCapacity)
  39. {
  40. passengers.IndexOf(i, passengerToFit);
  41. }
  42. }
  43. }
  44. }
  45. Console.WriteLine(string.Join(" ", passengers));
  46. }
  47. }
  48. }
RAW Paste Data