alexivanov2003

1

Feb 20th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _01TheFightForGondor
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.        
  11.         {
  12.             int n = int.Parse(Console.ReadLine());
  13.  
  14.             Queue<int> plates = new Queue<int>(Console.ReadLine()
  15.                 .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  16.                 .Select(int.Parse)
  17.                 .ToArray());
  18.             Queue<Stack<int>> waves = new Queue<Stack<int>>();
  19.             for (int i = 1; i <= n; i++)
  20.             {
  21.                 waves.Enqueue(new Stack<int>(Console.ReadLine()
  22.                     .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  23.                     .Select(int.Parse)
  24.                     .ToArray()));
  25.  
  26.                 if (i % 3 == 0)
  27.                 {
  28.                     plates.Enqueue(int.Parse(Console.ReadLine()));
  29.                 }
  30.             }
  31.  
  32.            
  33.             Stack<int> currentWave = waves.Dequeue();
  34.             int currentPlate = plates.Dequeue();
  35.  
  36.             while (waves.Count != 0 && plates.Count != 0)
  37.             {
  38.                
  39.                 if (currentWave.Count == 0)
  40.                 {
  41.                     currentWave = waves.Dequeue();
  42.                 }
  43.                 if (currentPlate == 0)
  44.                 {
  45.                     currentPlate = plates.Dequeue();
  46.                 }
  47.                
  48.                     int currentWarrior = currentWave.Pop();
  49.                     if (currentWarrior > currentPlate)
  50.                     {
  51.                         currentWarrior -= currentPlate;
  52.                         currentPlate = 0;
  53.                         currentWave.Push(currentWarrior);
  54.                     waves.Enqueue(currentWave);
  55.                         continue;
  56.                      
  57.                     }
  58.                     else if (currentWarrior < currentPlate)
  59.                     {
  60.                         currentPlate -= currentWarrior;                  
  61.                         continue;
  62.                      
  63.                     }
  64.                     else if (currentWarrior == currentPlate)
  65.                     {
  66.                     currentPlate = 0;
  67.                            
  68.                         continue;
  69.                     }                                
  70.             }
  71.             if (plates.Count == 0)
  72.             {
  73.                 Console.WriteLine($"The orcs successfully destroyed the Gondor's defense.");
  74.             }
  75.             else
  76.             {
  77.                 Console.WriteLine("The people successfully repulsed the orc's attack.");
  78.             }
  79.             if (plates.Count != 0)
  80.             {
  81.                 Console.WriteLine($"Plates left: {string.Join(" ", plates)}");
  82.             }
  83.             else
  84.             {
  85.                 while (waves.Count != 1)
  86.                 {
  87.                     waves.Dequeue();
  88.                 }
  89.                 Console.WriteLine($"Orcs left: {string.Join(", ", waves.Dequeue())}");
  90.                
  91.             }
  92.         }
  93.     }
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment