Advertisement
osman1997

01. the fight of gondor

Feb 23rd, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace ConsoleApp2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. int n = int.Parse(Console.ReadLine());
  13.  
  14. List<int> plates = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  15.  
  16. Stack<int> orcWaves = new Stack<int>();
  17.  
  18. for (int i = 1; i <= n; i++)
  19. {
  20. orcWaves = new Stack<int>(Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray());
  21.  
  22. if (i % 3 == 0)
  23. {
  24. int plate = int.Parse(Console.ReadLine());
  25. plates.Add(plate);
  26. }
  27. while (plates.Count != 0 && orcWaves.Count != 0)
  28. {
  29. int currentPlate = plates[0];
  30. int currentOrc = orcWaves.Pop();
  31.  
  32.  
  33. if (currentPlate < currentOrc)
  34. {
  35. currentOrc -= currentPlate;
  36. orcWaves.Push(currentOrc);
  37. plates.RemoveAt(0);
  38. }
  39. else if (currentOrc < currentPlate)
  40. {
  41. currentPlate -= currentOrc;
  42. plates[0] = currentPlate;
  43. }
  44. else
  45. {
  46. plates.RemoveAt(0);
  47. }
  48. }
  49. if (plates.Count == 0)
  50. {
  51. break;
  52. }
  53. }
  54.  
  55.  
  56. if (plates.Count == 0)
  57. {
  58. Console.WriteLine($"The orcs successfully destroyed the Gondor's defense.");
  59. Console.WriteLine($"Orcs left: {string.Join(", ", orcWaves)}");
  60. }
  61. else
  62. {
  63. Console.WriteLine("The people successfully repulsed the orc's attack.");
  64. Console.WriteLine($"Plates left: {string.Join(", ", plates)}");
  65. }
  66.  
  67. }
  68. }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement