Advertisement
bullit3189

Fast Food - StacksAndQueues

Apr 23rd, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. int food = int.Parse(Console.ReadLine());
  10.  
  11. int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13. Queue<int> orders = new Queue<int>(input);
  14.  
  15. int biggest = orders.Max();
  16.  
  17. if (food==0)
  18. {
  19. Console.WriteLine(biggest);
  20. Console.WriteLine("Orders left: {0}",string.Join(" ",orders));
  21. return;
  22. }
  23.  
  24. while (food>=0 && orders.Count>0)
  25. {
  26. int currOrder = orders.Peek();
  27.  
  28. if (currOrder<=food)
  29. {
  30. food-=currOrder;
  31. }
  32. else
  33. {
  34. break;
  35. }
  36.  
  37. orders.Dequeue();
  38. }
  39.  
  40. if (food>=0 && orders.Count==0)
  41. {
  42. Console.WriteLine(biggest);
  43. Console.WriteLine("Orders complete");
  44. }
  45. else
  46. {
  47. Console.WriteLine(biggest);
  48. Console.WriteLine("Orders left: {0}",string.Join(" ",orders));
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement