Advertisement
Guest User

Untitled

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