Advertisement
bullit3189

Trojan Invasion

May 28th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. int numWaves = int.Parse(Console.ReadLine());
  11.  
  12. int[] platesInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14. List<int> plates = new List<int>(platesInput);
  15. Stack<int> warriors = new Stack<int>();
  16.  
  17. for(int currWave = 1; currWave<=numWaves; currWave++)
  18. {
  19. if(plates.Count==0)
  20. {
  21. break;
  22. }
  23.  
  24. int[] warriorsInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  25.  
  26. foreach (var warrior in warriorsInput)
  27. {
  28. warriors.Push(warrior);
  29. }
  30.  
  31. if(currWave%3==0)
  32. {
  33. int toAdd = int.Parse(Console.ReadLine());
  34. plates.Add(toAdd);
  35. }
  36.  
  37. while(warriors.Any() && plates.Any())
  38. {
  39. int currWarrior = warriors.Peek();
  40. int currPlate = plates[0];
  41.  
  42. if(currWarrior == currPlate)
  43. {
  44. warriors.Pop();
  45. plates.Remove(currPlate);
  46. }
  47. else if (currWarrior < currPlate)
  48. {
  49. currPlate-=currWarrior;
  50. warriors.Pop();
  51. plates.RemoveAt(0);
  52. plates.Insert(0,currPlate);
  53. }
  54. else if (currWarrior > currPlate)
  55. {
  56. currWarrior-=currPlate;
  57. plates.RemoveAt(0);
  58. warriors.Pop();
  59. warriors.Push(currWarrior);
  60. }
  61. }
  62. }
  63.  
  64. if(plates.Any())
  65. {
  66. Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  67. Console.WriteLine("Plates left: {0}",string.Join(", ",plates));
  68. }
  69. else
  70. {
  71. Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  72. Console.WriteLine("Warriors left: {0}",string.Join(", ",warriors));
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement