SHARE
TWEET

Make Salad

KockataVelev3 Jun 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top