AnastasiyaG

Untitled

Feb 13th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exercise
  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 maxNumberOfPassenger = int.Parse(Console.ReadLine());
  16. string line = Console.ReadLine();
  17. while (line != "End")
  18. {
  19. List<string> command = line.Split().ToList();
  20. if (command[0] == "Add")
  21. { wagons.Add(int.Parse(command[1])); }
  22. else
  23. {
  24. int current = int.Parse(command[0]);
  25. FirstPossibleWagon(wagons, maxNumberOfPassenger, current);
  26.  
  27. }
  28. line = Console.ReadLine();
  29. }
  30. Console.WriteLine(String.Join(" ",wagons));
  31.  
  32. }
  33.  
  34. static void FirstPossibleWagon(List<int> wagons, int maxNumberOfPassenger, int current)
  35. {
  36. for (int i = 0; i <wagons.Count; i++)
  37. {
  38. if (wagons[i] + current <= maxNumberOfPassenger
  39. )
  40. { int total = wagons[i] + current;
  41. wagons[i] = total;
  42. break;
  43. }
  44.  
  45. }
  46. }
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment