Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Numerics;
- public class Program
- {
- public static void Main()
- {
- string[] vegetableInput = Console.ReadLine().Split();
- int[] caloriesInput = Console.ReadLine().Split().Select(int.Parse).ToArray();
- Queue<string> vegetables = new Queue<string>(vegetableInput);
- Stack<int> calories = new Stack<int>(caloriesInput);
- Stack<int> originalCalories = new Stack<int>(caloriesInput);
- List<int> salads = new List<int>();
- while(vegetables.Any() && calories.Any())
- {
- string currVegetable = vegetables.Dequeue();
- int currSalad = calories.Pop();
- int currVegCal = 0;
- switch(currVegetable)
- {
- case "tomato": currVegCal=80; break;
- case "carrot": currVegCal=136; break;
- case "lettuce": currVegCal=109; break;
- case "potato": currVegCal=215; break;
- }
- if(currVegCal>=currSalad)
- {
- salads.Add(originalCalories.Pop());
- }
- else
- {
- currSalad-=currVegCal;
- calories.Push(currSalad);
- }
- }
- if(calories.Any())
- {
- if(calories.Peek()!=originalCalories.Peek())
- {
- salads.Add(originalCalories.Peek());
- List<int>origCal = originalCalories.ToList();
- origCal.RemoveAt(0);
- origCal.Reverse();
- originalCalories.Clear();
- foreach(var item in origCal)
- {
- originalCalories.Push(item);
- }
- }
- Console.WriteLine(string.Join(" ",salads));
- Console.WriteLine(string.Join(" ",originalCalories));
- }
- else
- {
- Console.WriteLine(string.Join(" ",salads));
- Console.WriteLine(string.Join(" ",vegetables));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement