Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DemoExam16062019
- {
- class Program
- {
- static void Main(string[] args)
- {
- Queue<string> vegetables = new Queue<string>(Console.ReadLine().Split());
- Stack<int> calories = new Stack<int>(Console.ReadLine()
- .Split()
- .Select(int.Parse));
- var clone = new Stack<int>(calories.Reverse());
- List<int> readySalads = new List<int>();
- List<string> remainingItem = new List<string>();
- int caloriesToRemove = 0;
- while (true)
- {
- if (vegetables.Count == 0 || calories.Count == 0)
- {
- break;
- }
- string vegetable = vegetables.Peek();
- switch (vegetable)
- {
- case "tomato":
- caloriesToRemove = 80;
- break;
- case "carrot":
- caloriesToRemove = 136;
- break;
- case "lettuce":
- caloriesToRemove = 109;
- break;
- case "potato":
- caloriesToRemove = 215;
- break;
- }
- int caloriesNeeded = clone.Peek();
- int currentCalories = caloriesNeeded - caloriesToRemove;
- if (currentCalories >= 0)
- {
- vegetables.Dequeue();
- clone.Pop();
- clone.Push(currentCalories);
- }
- else if (currentCalories < 0)
- {
- vegetables.Dequeue();
- clone.Pop();
- readySalads.Add(calories.Peek());
- calories.Pop();
- }
- currentCalories = 0;
- }
- while (true)
- {
- if (vegetables.Count == 0 && calories.Count == 0)
- {
- break;
- }
- if (vegetables.Any())
- {
- remainingItem.Add(vegetables.Dequeue());
- }
- else if (calories.Any())
- {
- remainingItem.Add(calories.Pop().ToString());
- }
- }
- Console.WriteLine(string.Join(" ", readySalads));
- Console.WriteLine(string.Join(" ", remainingItem));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement