Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ExamPreparationStackAndQueues
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] guestsInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int[] platesInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
- Queue<int> guests = new Queue<int>(guestsInfo);
- Stack<int> plates = new Stack<int>(platesInfo);
- int overFood = 0;
- while (guests.Count != 0 && plates.Count != 0)
- {
- int currentGuest = guests.Peek();
- int currentPlate = plates.Peek();
- if (currentPlate >= currentGuest)
- {
- int currentOver = currentPlate - currentGuest;
- overFood += currentOver;
- guests.Dequeue();
- plates.Pop();
- }
- else if (currentGuest >= currentPlate)
- {
- while (currentGuest > 0)
- {
- if (currentPlate > currentGuest)
- {
- int currentOver = currentPlate - currentGuest;
- overFood += currentOver;
- }
- currentGuest -= currentPlate;
- plates.Pop();
- currentPlate = plates.Peek();
- }
- // currentGuest -= currentPlate;
- // plates.Pop();
- guests.Dequeue();
- }
- }
- if (guests.Count == 0)
- {
- Console.WriteLine("Plates: " + string.Join(" ", plates));
- Console.WriteLine($"Wasted grams of food: {overFood}");
- }
- else
- {
- Console.WriteLine("Guests: " + string.Join(" ", guests));
- Console.WriteLine($"Wasted grams of food: {overFood}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement