Advertisement
Guest User

Untitled

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