Advertisement
gabi11

Stacks and Queues - 04. Fast Food

May 10th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Advanced
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int foodQuantity = int.Parse(Console.ReadLine());
  14.             var orders = Console.ReadLine()
  15.                 .Split()
  16.                 .Select(int.Parse)
  17.                 .ToArray();
  18.             var queueOrders = new Queue<int>(orders);
  19.  
  20.             Console.WriteLine(orders.Max());
  21.  
  22.             while (queueOrders.Count > 0)
  23.             {
  24.                 var currentOrder = queueOrders.Peek();
  25.  
  26.                 if (currentOrder <= foodQuantity)
  27.                 {
  28.                     foodQuantity -= currentOrder;
  29.                     queueOrders.Dequeue();
  30.                 }
  31.  
  32.                 else
  33.                 {
  34.                     Console.WriteLine($"Orders left: {string.Join(" ", queueOrders)}");
  35.                     break;
  36.                 }
  37.             }
  38.  
  39.             if (queueOrders.Count == 0)
  40.             {
  41.                 Console.WriteLine("Orders complete");
  42.  
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement