svetlyoek

Untitled

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