Advertisement
VickSuna

Untitled

Oct 2nd, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparationStackAndQueues
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int[] guestsInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12. int[] platesInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13. Queue<int> guests = new Queue<int>(guestsInfo);
  14. Stack<int> plates = new Stack<int>(platesInfo);
  15. int overFood = 0;
  16.  
  17.  
  18.  
  19.  
  20. while (guests.Count != 0 && plates.Count != 0)
  21. {
  22.  
  23. int currentGuest = guests.Peek();
  24. int currentPlate = plates.Peek();
  25.  
  26. if (currentPlate >= currentGuest)
  27. {
  28.  
  29. int currentOver = currentPlate - currentGuest;
  30. overFood += currentOver;
  31. guests.Dequeue();
  32. plates.Pop();
  33. }
  34. else
  35. {
  36. while (currentGuest > 0)
  37. {
  38. if (currentPlate > currentGuest)
  39. {
  40. int currentOver = currentPlate - currentGuest;
  41. overFood += currentOver;
  42. }
  43.  
  44. currentGuest -= currentPlate;
  45. plates.Pop();
  46.  
  47. if (plates.Any())
  48. {
  49. currentPlate = plates.Peek();
  50. }
  51. else
  52. {
  53. continue;
  54. }
  55. }
  56. // currentGuest -= currentPlate;
  57. // plates.Pop();
  58. guests.Dequeue();
  59. }
  60.  
  61. }
  62. if (guests.Count == 0)
  63. {
  64. Console.WriteLine("Plates: " + string.Join(" ", plates));
  65. Console.WriteLine($"Wasted grams of food: {overFood}");
  66. }
  67. else
  68. {
  69. Console.WriteLine("Guests: " + string.Join(" ", guests));
  70. Console.WriteLine($"Wasted grams of food: {overFood}");
  71. }
  72.  
  73.  
  74. }
  75. }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement