Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P01._Train
  6. {
  7. class StartUp
  8. {
  9.  
  10.  
  11. static void Main()
  12. {
  13. List<int> wagonsPeople = Console.ReadLine().Split().Select(int.Parse).ToList();
  14. int maxPeople = int.Parse(Console.ReadLine());
  15. string command = Console.ReadLine();
  16. List<int> finalList = new List<int>();
  17.  
  18. while (true)
  19. {
  20. if (command == "end")
  21. {
  22. foreach (var people in wagonsPeople)
  23. {
  24. Console.Write(people + " ");
  25. }
  26. Console.WriteLine();
  27. break;
  28. }
  29. string[] actions = command.Split().ToArray();
  30. if (actions[0] == "Add")
  31. {
  32. int countPeople = int.Parse(actions[1]);
  33. wagonsPeople.Add(countPeople);
  34. }
  35. else
  36. {
  37. finalList = AddPeopleIfPossible(wagonsPeople, int.Parse(actions[0]), maxPeople);
  38. }
  39. command = Console.ReadLine();
  40. }
  41.  
  42. }
  43.  
  44. public static List<int> AddPeopleIfPossible(List<int> wagonsPeople, int people, int max)
  45. {
  46.  
  47. for (int i = 0; i < wagonsPeople.Count; i++)
  48. {
  49. if (people + wagonsPeople[i] > max)
  50. {
  51. continue;
  52. }
  53. else
  54. {
  55. wagonsPeople[i] += people;
  56. return wagonsPeople;
  57. }
  58. }
  59. return wagonsPeople;
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement