Advertisement
Silviya7

01. Bakery Shop

Mar 23rd, 2023
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1.  
  2. using Exam20February2022;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. namespace Exam20February2022
  8. {
  9.     public class StartUp
  10.     {
  11.         private class BakedProducts
  12.         {
  13.             public BakedProducts(string nameofProduct, int neeededWater, int neededloor)
  14.             {
  15.                 this.NameProduct = nameofProduct;
  16.                 this.RatioWater = neeededWater;
  17.                 this.RatioFloor = neededloor;
  18.             }
  19.             public string NameProduct { get; set; }
  20.             public int RatioWater { get; set; }
  21.             public int RatioFloor { get; set; }
  22.  
  23.         }
  24.         public static void Main(string[] args)
  25.         {
  26.  
  27.  
  28.             BakedProducts prod1 = new BakedProducts("Croissant", 50, 50);
  29.  
  30.             BakedProducts prod2 = new BakedProducts("Muffin", 40, 60);
  31.  
  32.             BakedProducts prod3 = new BakedProducts("Baguette", 30, 70);
  33.  
  34.             BakedProducts prod4 = new BakedProducts("Bagel", 20, 80);
  35.  
  36.             List<BakedProducts> ListBakedProd = new List<BakedProducts>();
  37.  
  38.             ListBakedProd.Add(prod1);
  39.             ListBakedProd.Add(prod2);
  40.             ListBakedProd.Add(prod3);
  41.             ListBakedProd.Add(prod4);
  42.  
  43.             //Queue  water
  44.             //STack   flour
  45.             Dictionary<string, int> BakedProductsFinish = new Dictionary<string, int>();
  46.  
  47.             Queue<double> amountwater = new Queue<double>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse));
  48.             Stack<double> amountfloor = new Stack<double>(Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(double.Parse));
  49.  
  50.             while (true)
  51.             {
  52.  
  53.                 if (amountwater.Count == 0 || amountfloor.Count == 0)
  54.                 {
  55.                     break;
  56.                 }
  57.                 double CommonProd = amountwater.Peek() + amountfloor.Peek();
  58.  
  59.                 double Persentwater = (amountwater.Peek() * 100) / CommonProd;
  60.  
  61.                 int Persentwaternew = (int)Persentwater;
  62.                 int PersentFloor = 100 - Persentwaternew;
  63.  
  64.                 BakedProducts baked1 = ListBakedProd.FirstOrDefault(p => p.RatioWater == Persentwaternew && p.RatioFloor == PersentFloor);
  65.  
  66.                 if (baked1 != null)//Ima go v tablicata na izpe4enite
  67.                 {
  68.                     amountwater.Dequeue();
  69.                     amountfloor.Pop();
  70.  
  71.                     if (BakedProductsFinish.ContainsKey(baked1.NameProduct))
  72.                     {
  73.                         BakedProductsFinish[baked1.NameProduct]++;
  74.                     }
  75.                     else
  76.                     {
  77.  
  78.                         BakedProductsFinish.Add(baked1.NameProduct, 1);
  79.                     }
  80.  
  81.                 }
  82.                 else //Not in Table
  83.                 {
  84.                     double Remainint = amountfloor.Peek() - amountwater.Peek();
  85.  
  86.                     int RemainLast = (int)Remainint;
  87.                     amountfloor.Pop();
  88.                     amountfloor.Push(Remainint);//Update
  89.  
  90.                     amountwater.Dequeue();
  91.                     if (BakedProductsFinish.ContainsKey("Croissant"))
  92.                     {
  93.                         BakedProductsFinish[baked1.NameProduct]++;
  94.                     }
  95.                     else
  96.                     {
  97.  
  98.                         BakedProductsFinish.Add("Croissant", 1);
  99.                     }
  100.  
  101.                 }
  102.  
  103.  
  104.  
  105.             }//while end
  106.             foreach (var bakedProduct in BakedProductsFinish.OrderByDescending(p => p.Value).ThenBy(p => p.Key))
  107.             {
  108.                 Console.WriteLine($"{bakedProduct.Key}: {bakedProduct.Value}");
  109.             }
  110.  
  111.             if (amountwater.Count == 0)
  112.             {
  113.                 Console.WriteLine($"Water left: None");
  114.             }
  115.             else
  116.             {
  117.                 string LeftWater = string.Join(", ", amountwater);
  118.                 Console.WriteLine("Water left: " + LeftWater);
  119.             }
  120.  
  121.             if (amountfloor.Count == 0)
  122.             {
  123.                 Console.WriteLine($"Flour left: None");
  124.             }
  125.             else
  126.             {
  127.                 string leftFloor = string.Join(", ", amountfloor);
  128.                 Console.WriteLine("Flour left: " + leftFloor);
  129.             }
  130.  
  131.         }
  132.  
  133.     }
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement