Advertisement
Guest User

Untitled

a guest
Jun 13th, 2020
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Catapult_Attack
  6. {
  7. public class StartUp
  8. {
  9. public static void Main()
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. List<int> wallList = Console.ReadLine()
  14. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToList();
  17. Stack<int> rockStack = new Stack<int>();
  18.  
  19. for (int i = 1; i <= n; i++)
  20. {
  21. List<int> rockList = Console.ReadLine()
  22. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  23. .Select(int.Parse)
  24. .ToList();
  25. AddWarriors(rockStack, rockList);
  26.  
  27. if (i % 3 == 0)
  28. {
  29. int additionalWall = int.Parse(Console.ReadLine());
  30. wallList.Add(additionalWall);
  31. }
  32.  
  33. while (rockStack.Count > 0 && wallList.Count > 0)
  34. {
  35. int currentRock = rockStack.Pop();
  36. int currentWall = wallList[0];
  37.  
  38. if (currentRock > currentWall)
  39. {
  40. currentRock -= currentWall;
  41. rockStack.Push(currentRock);
  42. wallList.RemoveAt(0);
  43. }
  44. else if (currentRock < currentWall)
  45. {
  46. currentWall -= currentRock;
  47. wallList[0] = currentWall;
  48. }
  49. else
  50. {
  51. wallList.RemoveAt(0);
  52. }
  53. }
  54.  
  55. if (wallList.Count == 0)
  56. {
  57. break;
  58. }
  59. }
  60.  
  61. PrintOutput(wallList, rockStack);
  62. }
  63.  
  64. private static void PrintOutput(List<int> wallList, Stack<int> rockStack)
  65. {
  66. if (wallList.Count == 0)
  67. {
  68.  
  69. Console.WriteLine($"Rocks left: {String.Join(", ", rockStack)}");
  70. }
  71. else
  72. {
  73.  
  74. Console.WriteLine($"Walls left: {String.Join(", ", wallList)}");
  75. }
  76. }
  77.  
  78. private static void AddWarriors(Stack<int> rockStack, List<int> rockList)
  79. {
  80. foreach (var war in rockList)
  81. {
  82. rockStack.Push(war);
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement