Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01._Trojan_Invasion
  6. {
  7. class StartUp
  8. {
  9. static void Main(string[] args)
  10. {
  11. int countWaves = int.Parse(Console.ReadLine());
  12.  
  13. int[] platesInput = Console.ReadLine()
  14. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToArray();
  17.  
  18. Queue<int> plates = new Queue<int>(platesInput);
  19. Stack<int> waveToPrint = new Stack<int>();
  20.  
  21. bool trojansWin = false;
  22.  
  23. for (int i = 1; i <= countWaves; i++)
  24. {
  25. int[] waveInfo = Console.ReadLine()
  26. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  27. .Select(int.Parse)
  28. .ToArray();
  29.  
  30. Stack<int> cuurentWave = new Stack<int>(waveInfo);
  31.  
  32. if (i % 3 == 0)
  33. {
  34. int additionalPlate = int.Parse(Console.ReadLine());
  35. plates.Enqueue(additionalPlate);
  36. }
  37.  
  38. while (cuurentWave.Any() && plates.Any())
  39. {
  40. if (cuurentWave.Peek() > plates.Peek())
  41. {
  42. int newWarriorValue = cuurentWave.Pop() - plates.Dequeue();
  43. cuurentWave.Push(newWarriorValue);
  44.  
  45. if (!plates.Any())
  46. {
  47. waveToPrint = new Stack<int>(cuurentWave);
  48. trojansWin = true;
  49. break;
  50. }
  51. }
  52. else if (cuurentWave.Peek() == plates.Peek())
  53. {
  54. plates.Dequeue();
  55. cuurentWave.Pop();
  56. }
  57. else if (cuurentWave.Peek() < plates.Peek())
  58. {
  59. int newPlateValue = plates.Dequeue() - cuurentWave.Pop();
  60.  
  61. List<int> temp = new List<int>(plates.Reverse());
  62. temp.Add(newPlateValue);
  63. temp.Reverse();
  64.  
  65. plates = new Queue<int>(temp);
  66. }
  67. }
  68. }
  69.  
  70. if (trojansWin)
  71. {
  72. Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  73.  
  74. if (waveToPrint.Count > 0)
  75. {
  76. Console.Write("Warriors left: ");
  77. Console.WriteLine(String.Join(", ", waveToPrint.Reverse()));
  78. }
  79. }
  80. else
  81. {
  82. Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  83.  
  84. if (plates.Count > 0)
  85. {
  86. Console.Write("Plates left: ");
  87. Console.WriteLine(String.Join(", ", plates));
  88. }
  89. }
  90. }
  91. }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement