Advertisement
Guest User

Untitled

a guest
Jun 21st, 2019
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 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 Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int numberOfWaves = int.Parse(Console.ReadLine());
  12.  
  13. List<int> plates = Console.ReadLine()
  14. .Split()
  15. .Select(int.Parse)
  16. .ToList();
  17.  
  18.  
  19. Stack<int> warriors = new Stack<int>();
  20.  
  21. for (int i = 1; i <= numberOfWaves; i++)
  22. {
  23. if (plates.Count == 0)
  24. {
  25. break;
  26. }
  27. int[] warrior = Console.ReadLine()
  28. .Split()
  29. .Select(int.Parse)
  30. .ToArray();
  31.  
  32.  
  33. if (i% 3 == 0)
  34. {
  35. int addPlate = int.Parse(Console.ReadLine());
  36. plates.Add(addPlate);
  37. }
  38.  
  39. foreach (var war in warrior)
  40. {
  41. warriors.Push(war);
  42. }
  43. while (plates.Count > 0 && warriors.Count > 0)
  44. {
  45. int currentWarrior = warriors.Pop();
  46. int currentPlates = plates[0];
  47.  
  48. if (currentPlates > currentWarrior)
  49. {
  50. currentPlates -= currentWarrior;
  51. plates[0] = currentPlates;
  52. }
  53. else if (currentPlates < currentWarrior)
  54. {
  55. currentWarrior -= currentPlates;
  56. warriors.Push(currentWarrior);
  57. plates.RemoveAt(0);
  58. }
  59. else
  60. {
  61. plates.RemoveAt(0);
  62. }
  63.  
  64. }
  65. }
  66. if (warriors.Count > 0)
  67. {
  68. Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  69.  
  70. Console.Write($"Warriors left: {string.Join(", ", warriors)}");
  71.  
  72. }
  73. else
  74. {
  75. Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  76.  
  77. Console.Write($"Plates left: { string.Join(", ", plates)}");
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement