Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Make_a_Salad
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string[] allVegetables = Console.ReadLine().Split();
  12. int[] allCalories =Console.ReadLine()
  13. .Split()
  14. .Select(int.Parse)
  15. .ToArray();
  16.  
  17. Stack<int> calories = new Stack<int>(allCalories);
  18. Queue<string> vegetable = new Queue<string>(allVegetables);
  19. List<int> salad = new List<int>();
  20. int caloriesVegetable = 0;
  21. int residue = 0;
  22.  
  23. while (vegetable.Count > 0 && calories.Count > 0)
  24. {
  25.  
  26.  
  27. if (vegetable.Peek() == "tomato")
  28. {
  29. caloriesVegetable = 80;
  30. }
  31. else if (vegetable.Peek() == "carrot")
  32. {
  33. caloriesVegetable = 136;
  34. }
  35. else if (vegetable.Peek() == "lettuce")
  36. {
  37. caloriesVegetable = 109;
  38. }
  39. else if (vegetable.Peek() == "potato")
  40. {
  41. caloriesVegetable = 215;
  42. }
  43.  
  44. if (calories.Peek() <= caloriesVegetable)
  45. {
  46. vegetable.Dequeue();
  47. residue += caloriesVegetable - calories.Peek();
  48. salad.Add(calories.Pop());
  49.  
  50. }
  51. else if (calories.Peek() > caloriesVegetable)
  52. {
  53. residue += caloriesVegetable;
  54. vegetable.Dequeue();
  55. if (residue >= calories.Peek())
  56. {
  57. residue = residue - calories.Peek();
  58.  
  59. salad.Add(calories.Pop());
  60. }
  61. }
  62. }
  63.  
  64. Console.Write(String.Join(" ",salad));
  65.  
  66.  
  67. Console.WriteLine();
  68. if (vegetable.Count > 0)
  69. {
  70. Console.Write(string.Join(" ", vegetable));
  71.  
  72. Console.WriteLine();
  73. }
  74. else if (calories.Count > 0)
  75. {
  76. Console.Write(string.Join(" ", calories));
  77.  
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement