Advertisement
bullit3189

Make a Salad

Jun 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Numerics;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. string[] vegetableInput = Console.ReadLine().Split();
  12. int[] caloriesInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14. Queue<string> vegetables = new Queue<string>(vegetableInput);
  15. Stack<int> calories = new Stack<int>(caloriesInput);
  16. Stack<int> originalCalories = new Stack<int>(caloriesInput);
  17.  
  18. List<int> salads = new List<int>();
  19.  
  20. while(vegetables.Any() && calories.Any())
  21. {
  22. string currVegetable = vegetables.Dequeue();
  23. int currSalad = calories.Pop();
  24.  
  25. int currVegCal = 0;
  26.  
  27. switch(currVegetable)
  28. {
  29. case "tomato": currVegCal=80; break;
  30. case "carrot": currVegCal=136; break;
  31. case "lettuce": currVegCal=109; break;
  32. case "potato": currVegCal=215; break;
  33. }
  34.  
  35. if(currVegCal>=currSalad)
  36. {
  37. salads.Add(originalCalories.Pop());
  38. }
  39. else
  40. {
  41. currSalad-=currVegCal;
  42. calories.Push(currSalad);
  43. }
  44. }
  45.  
  46.  
  47.  
  48. if(calories.Any())
  49. {
  50. if(calories.Peek()!=originalCalories.Peek())
  51. {
  52. salads.Add(originalCalories.Peek());
  53.  
  54. List<int>origCal = originalCalories.ToList();
  55. origCal.RemoveAt(0);
  56. origCal.Reverse();
  57.  
  58. originalCalories.Clear();
  59.  
  60. foreach(var item in origCal)
  61. {
  62. originalCalories.Push(item);
  63. }
  64. }
  65. Console.WriteLine(string.Join(" ",salads));
  66. Console.WriteLine(string.Join(" ",originalCalories));
  67. }
  68. else
  69. {
  70. Console.WriteLine(string.Join(" ",salads));
  71. Console.WriteLine(string.Join(" ",vegetables));
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement