Advertisement
Guest User

Train

a guest
Feb 20th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01Train
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> wagons = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15. int maxCapacityOfEachWagon = int.Parse(Console.ReadLine());
  16. string command = Console.ReadLine();
  17.  
  18. while (command != "end")
  19. {
  20. List<string> directions = command.Split().ToList();
  21. if (directions[0] == "Add")
  22. {
  23. int custemersInWagon = int.Parse(directions[1]);
  24. wagons.Add(custemersInWagon);
  25. }
  26. else
  27. {
  28. int passangerToFit = int.Parse(directions[0]);
  29. for (int i = 0; i < wagons.Count; i++)
  30. {
  31. if (wagons[i] + passangerToFit <= maxCapacityOfEachWagon)
  32. {
  33. wagons[i] += passangerToFit;
  34. break;
  35. }
  36.  
  37. }
  38. }
  39.  
  40. }
  41. Console.WriteLine(string.Join(" ", wagons));
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement