Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _02._Make_a_Salad
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] allVegetables = Console.ReadLine().Split();
- int[] allCalories =Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- Stack<int> calories = new Stack<int>(allCalories);
- Queue<string> vegetable = new Queue<string>(allVegetables);
- List<int> salad = new List<int>();
- int caloriesVegetable = 0;
- int residue = 0;
- while (vegetable.Count > 0 && calories.Count > 0)
- {
- if (vegetable.Peek() == "tomato")
- {
- caloriesVegetable = 80;
- }
- else if (vegetable.Peek() == "carrot")
- {
- caloriesVegetable = 136;
- }
- else if (vegetable.Peek() == "lettuce")
- {
- caloriesVegetable = 109;
- }
- else if (vegetable.Peek() == "potato")
- {
- caloriesVegetable = 215;
- }
- if (calories.Peek() <= caloriesVegetable)
- {
- vegetable.Dequeue();
- residue += caloriesVegetable - calories.Peek();
- salad.Add(calories.Pop());
- }
- else if (calories.Peek() > caloriesVegetable)
- {
- residue += caloriesVegetable;
- vegetable.Dequeue();
- if (residue >= calories.Peek())
- {
- residue = residue - calories.Peek();
- salad.Add(calories.Pop());
- }
- }
- }
- Console.Write(String.Join(" ",salad));
- Console.WriteLine();
- if (vegetable.Count > 0)
- {
- Console.Write(string.Join(" ", vegetable));
- Console.WriteLine();
- }
- else if (calories.Count > 0)
- {
- Console.Write(string.Join(" ", calories));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement