anizko

04. Fast Food 80/100

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