Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _01TrojanInvasion2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int walesNumber = int.Parse(Console.ReadLine());
  12.  
  13. var plates = Console.ReadLine()
  14. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToList();
  17. //Queue<int> platesQueue = new Queue<int>();
  18.  
  19. Stack<int> warriors = new Stack<int>();
  20.  
  21. // for (int i = 0; i < plates.Length; i++)
  22. // {
  23. // platesQueue.Enqueue(plates[i]);
  24. // }
  25.  
  26. for (int row = 1; row <= walesNumber; row++)
  27. {
  28. if (plates.Count == 0)
  29. {
  30. break;
  31. }
  32.  
  33. int[] currentWaveWarriors = Console.ReadLine()
  34. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  35. .Select(int.Parse)
  36. .ToArray();
  37.  
  38. if (row % 3 == 0)
  39. {
  40. int extraPlate = int.Parse(Console.ReadLine());
  41. plates.Add(extraPlate);
  42. }
  43.  
  44. for (int warrior = 0; warrior < currentWaveWarriors.Length; warrior++)
  45. {
  46. warriors.Push(currentWaveWarriors[warrior]);
  47. }
  48.  
  49.  
  50.  
  51. while (warriors.Count > 0 && plates.Count>0)
  52. {
  53. int currentWarrior = warriors.Pop();
  54. int currentPlate = plates[0];
  55.  
  56. if (currentPlate > currentWarrior)
  57. {
  58. currentPlate -= currentWarrior;
  59. plates[0] = currentPlate;
  60. }
  61. else if (currentPlate < currentWarrior)
  62. {
  63. currentWarrior -= currentPlate;
  64. warriors.Push(currentWarrior);
  65. plates.RemoveAt(0);
  66. }
  67. else
  68. {
  69. plates.RemoveAt(0);
  70. }
  71. }
  72. }
  73.  
  74. if (warriors.Count > 0)
  75. {
  76. Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  77. Console.WriteLine($"Warriors left: {string.Join(", ", warriors)}");
  78. }
  79. else
  80. {
  81. Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  82. Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement