Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Catapult_Attack
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. var pilesCount = int.Parse(Console.ReadLine());
  12.  
  13. var wallsInput = Console
  14. .ReadLine()
  15. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  16. .Select(int.Parse)
  17. .ToArray();
  18.  
  19. var walls = new Queue<int>(wallsInput);
  20. var rocks = new Stack<int>();
  21.  
  22. for (int i = 1; i <= pilesCount; i++)
  23. {
  24.  
  25. var curPile = Console
  26. .ReadLine()
  27. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  28. .Select(int.Parse)
  29. .ToList();
  30.  
  31. if (!walls.Any())
  32. {
  33. Console.WriteLine($"Rocks left: {string.Join(", ", rocks)}");
  34. break;
  35. }
  36.  
  37. if (i % 3 == 0)
  38. {
  39. walls.Enqueue(int.Parse(Console.ReadLine()));
  40. }
  41.  
  42. foreach (var curRock in curPile)
  43. {
  44. rocks.Push(curRock);
  45. }
  46.  
  47. while (rocks.Any() && walls.Any())
  48. {
  49. var rock = rocks.Pop();
  50. var wall = walls.Dequeue();
  51.  
  52. if (rock > wall)
  53. {
  54. rocks.Push(rock - wall);
  55. }
  56.  
  57. else if (rock < wall)
  58. {
  59. walls.Enqueue(wall - rock);
  60.  
  61. for (int j = 0; j < walls.Count - 1; j++)
  62. {
  63. walls.Enqueue(walls.Dequeue());
  64. }
  65. }
  66. }
  67. }
  68.  
  69. if (!rocks.Any())
  70. {
  71. Console.WriteLine($"Walls left: {string.Join(", ", walls)}");
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement