Advertisement
VickSuna

Untitled

Oct 2nd, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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 if (currentGuest >= currentPlate)
  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. currentPlate = plates.Peek();
  47.  
  48. }
  49. // currentGuest -= currentPlate;
  50. // plates.Pop();
  51. guests.Dequeue();
  52. }
  53.  
  54. }
  55. if (guests.Count == 0)
  56. {
  57. Console.WriteLine("Plates: " + string.Join(" ", plates));
  58. Console.WriteLine($"Wasted grams of food: {overFood}");
  59. }
  60. else
  61. {
  62. Console.WriteLine("Guests: " + string.Join(" ", guests));
  63. Console.WriteLine($"Wasted grams of food: {overFood}");
  64. }
  65.  
  66.  
  67. }
  68. }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement