Teo_Yanchev

ListsExercise - Train - C# Fundamentals

Sep 19th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5.  
  6. namespace ListsExercise
  7. {
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. List<int> wagons = Console.ReadLine()
  13. .Split()
  14. .Select(int.Parse)
  15. .ToList();
  16. int maxCapacity = int.Parse(Console.ReadLine());
  17.  
  18. List<string> line = Console.ReadLine()
  19. .Split()
  20. .ToList();
  21. while (line[0] != "end")
  22. {
  23.  
  24. if (line[0] == "Add")
  25. {
  26. if (int.Parse(line[1]) <= maxCapacity)
  27. {
  28. wagons.Add(int.Parse(line[1]));
  29. }
  30. else
  31. {
  32. line = Console.ReadLine()
  33. .Split()
  34. .ToList();
  35. continue;
  36.  
  37. }
  38. }
  39.  
  40. else
  41. {
  42. int lineNumber = int.Parse(line[0]);
  43. int PassengersInWagons = 0;
  44. for (int i = 0; i < wagons.Count; i++)
  45. {
  46. int diffInPassengers = maxCapacity - wagons[i];
  47.  
  48. if (lineNumber <= diffInPassengers)
  49. {
  50. PassengersInWagons = lineNumber + wagons[i];
  51. wagons.Insert(i, PassengersInWagons);
  52. wagons.RemoveAt(i + 1);
  53. break;
  54. }
  55. }
  56. }
  57.  
  58. line = Console.ReadLine()
  59. .Split()
  60. .ToList();
  61. }
  62.  
  63. Console.WriteLine(string.Join(" ", wagons));
  64. }
  65. }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment