Advertisement
Iv555

Untitled

Feb 8th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace T01BirthdayCelebration
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. int[] guestsQueue = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  13. int[] platesStack = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  14.  
  15. Queue<int> guests = new Queue<int>(guestsQueue);
  16. Stack<int> plates = new Stack<int>(platesStack);
  17.  
  18. int wastedFood = 0;
  19. while (guests.Count > 0 && plates.Count > 0)
  20. {
  21.  
  22. if (guests.Peek() < plates.Peek())
  23. {
  24. wastedFood += plates.Pop() - guests.Dequeue();
  25. }
  26. else if (guests.Peek() > plates.Peek())
  27. {
  28. Queue<int> newGuestsRow = new Queue<int>();
  29. newGuestsRow.Enqueue(guests.Dequeue() - plates.Pop());
  30.  
  31. for (int i = 0; i < guests.Count; i++)
  32. {
  33. newGuestsRow.Enqueue(guests.ElementAt(i));
  34. }
  35.  
  36. guests = newGuestsRow;
  37. }
  38. else
  39. {
  40. guests.Dequeue();
  41. plates.Pop();
  42. }
  43.  
  44. }
  45.  
  46. if (plates.Count == 0)
  47. {
  48. Console.WriteLine($"Guests: {string.Join(" ", guests)}");
  49. Console.WriteLine($"Wasted grams of food: {wastedFood}");
  50. }
  51. else if (guests.Count == 0)
  52. {
  53. Console.WriteLine($"Plates: {string.Join(" ", plates)}");
  54. Console.WriteLine($"Wasted grams of food: {wastedFood}");
  55. }
  56.  
  57. }
  58. }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement