Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Exam20February2022;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam20February2022
- {
- public class StartUp
- {
- private class BakedProducts
- {
- public BakedProducts(string nameofProduct, int neeededWater, int neededloor)
- {
- this.NameProduct = nameofProduct;
- this.RatioWater = neeededWater;
- this.RatioFloor = neededloor;
- }
- public string NameProduct { get; set; }
- public int RatioWater { get; set; }
- public int RatioFloor { get; set; }
- }
- public static void Main(string[] args)
- {
- BakedProducts prod1 = new BakedProducts("Croissant", 50, 50);
- BakedProducts prod2 = new BakedProducts("Muffin", 40, 60);
- BakedProducts prod3 = new BakedProducts("Baguette", 30, 70);
- BakedProducts prod4 = new BakedProducts("Bagel", 20, 80);
- List<BakedProducts> ListBakedProd = new List<BakedProducts>();
- ListBakedProd.Add(prod1);
- ListBakedProd.Add(prod2);
- ListBakedProd.Add(prod3);
- ListBakedProd.Add(prod4);
- //Queue water
- //STack flour
- Dictionary<string, int> BakedProductsFinish = new Dictionary<string, int>();
- Queue<double> amountwater = new Queue<double>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse));
- Stack<double> amountfloor = new Stack<double>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse));
- while (true)
- {
- if (amountwater.Count == 0 || amountfloor.Count == 0)
- {
- break;
- }
- double CommonProd = amountwater.Peek() + amountfloor.Peek();
- double Persentwater = (amountwater.Peek() * 100) / CommonProd;
- int Persentwaternew = (int)Persentwater;
- int PersentFloor = 100 - Persentwaternew;
- BakedProducts baked1 = ListBakedProd.FirstOrDefault(p => p.RatioWater == Persentwaternew && p.RatioFloor == PersentFloor);
- if (baked1 != null)//Ima go v tablicata na izpe4enite
- {
- amountwater.Dequeue();
- amountfloor.Pop();
- if (BakedProductsFinish.ContainsKey(baked1.NameProduct))
- {
- BakedProductsFinish[baked1.NameProduct]++;
- }
- else
- {
- BakedProductsFinish.Add(baked1.NameProduct, 1);
- }
- }
- else //Not in Table
- {
- double Remainint = amountfloor.Peek() - amountwater.Peek();
- int RemainLast = (int)Remainint;
- amountfloor.Pop();
- amountfloor.Push(Remainint);//Update
- amountwater.Dequeue();
- if (BakedProductsFinish.ContainsKey("Croissant"))
- {
- BakedProductsFinish[baked1.NameProduct]++;
- }
- else
- {
- BakedProductsFinish.Add("Croissant", 1);
- }
- }
- }//while end
- foreach (var bakedProduct in BakedProductsFinish.OrderByDescending(p => p.Value).ThenBy(p => p.Key))
- {
- Console.WriteLine($"{bakedProduct.Key}: {bakedProduct.Value}");
- }
- if (amountwater.Count == 0)
- {
- Console.WriteLine($"Water left: None");
- }
- else
- {
- string LeftWater = string.Join(", ", amountwater);
- Console.WriteLine("Water left: " + LeftWater);
- }
- if (amountfloor.Count == 0)
- {
- Console.WriteLine($"Flour left: None");
- }
- else
- {
- string leftFloor = string.Join(", ", amountfloor);
- Console.WriteLine("Flour left: " + leftFloor);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement