marangoni

Untitled

Feb 20th, 2020
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Trojan_Invasion
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int waves = int.Parse(Console.ReadLine());
  12.             bool IsTrojanWin = false;
  13.  
  14.             Stack<int> wariors = new Stack<int>();  //push,Pop,Peek
  15.  
  16.             int[] plateTemp = Console.ReadLine()
  17.                 .Split()
  18.                 .Select(int.Parse)
  19.                 .ToArray();
  20.  
  21.             List<int> plates = new List<int>(plateTemp);
  22.  
  23.             for (int i = 1; i <= waves; i++)
  24.             {
  25.                 if (i % 3 == 0)
  26.                 {
  27.                     //int addNewPlate = 0;
  28.  
  29.                     int[] warriorTemp = Console.ReadLine().Split().Select(int.Parse).ToArray();
  30.  
  31.                     for (int e = 0; e < warriorTemp.Length; e++)
  32.                     {
  33.                         wariors.Push(warriorTemp[e]);
  34.                     }
  35.                     int[] boom = Console.ReadLine().Split().Select(int.Parse).ToArray();
  36.                     // plates.IndexOf(addNewPlate, 0);
  37.                     plates.Add(boom[0]);
  38.                 }
  39.                 else
  40.                 {
  41.                     int[] warriorTemp = Console.ReadLine().Split().Select(int.Parse).ToArray();
  42.  
  43.                     for (int j = 0; j < warriorTemp.Length; j++)
  44.                     {
  45.                         wariors.Push(warriorTemp[j]);
  46.                     }
  47.                 }
  48.  
  49.  
  50.                 while (plates.Count > 0 && wariors.Count > 0)
  51.                 {
  52.                     if (plates[0] > wariors.Peek())
  53.                     {
  54.                         plates[0] = plates[0] - wariors.Peek();
  55.                         wariors.Pop();
  56.                     }
  57.                     else if (wariors.Peek() > plates[0])
  58.                     {
  59.                         wariors.Push(wariors.Pop() - plates[0]);
  60.                         plates.RemoveAt(0);
  61.                     }
  62.                     else if (wariors.Peek() == plates[0])
  63.                     {
  64.                         wariors.Pop();
  65.                         plates.RemoveAt(0);
  66.                        
  67.                     }
  68.                     if (wariors.Count == 0)
  69.                     {
  70.                         break;
  71.                     }
  72.                     if (plates.Count == 0)
  73.                     {
  74.                        
  75.                         Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  76.                         Console.WriteLine($"Warriors left: {string.Join(", ", wariors)}");
  77.                         IsTrojanWin = true;
  78.                         break;
  79.                        
  80.                     }
  81.                 }
  82.                 if (IsTrojanWin)
  83.                 {
  84.                     break;
  85.                 }
  86.                 if (plates.Count == 0 && wariors.Count > 0 && i == waves)
  87.                 {
  88.                     Console.WriteLine("The Trojans successfully destroyed the Spartan defense.");
  89.                     Console.WriteLine($"Warriors left: {string.Join(", ", wariors)}");
  90.                     break;
  91.                 }
  92.                 else if (wariors.Count == 0 && plates.Count > 0 && i == waves)
  93.                 {
  94.                     Console.WriteLine("The Spartans successfully repulsed the Trojan attack.");
  95.                     Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
  96.                     break;
  97.                 }
  98.             }
  99.         }      
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment