Advertisement
KockataVelev3

Make Salad

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