using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { class Program { class main{ public static void Main() { static string Get() { return Console.ReadLine(); } List Items = new List(); List Boxes = new List(); while (true) { string command = Get(); if (command == "end") { break; } else { string[] data = command.Split(' ').ToArray(); int this_SerialN = Convert.ToInt32(data[0]); int this_ItemQuantity = Convert.ToInt32(data[2]); double this_ItemPrice = double.Parse(data[3]); string this_ItemName = data[1]; double this_PriceOfBox = this_ItemPrice * this_ItemQuantity; //------------------------------------------------ Box thisBox = new Box(); Item thisItem = new Item(); //---------------------------------- thisItem.name = this_ItemName; thisItem.Price = this_ItemPrice; thisBox.Item = thisItem; thisBox.SerialNumber = this_SerialN; thisBox.ItemQuantity = this_ItemQuantity; thisBox.BoxPrice = this_PriceOfBox; Items.Add(thisItem); Boxes.Add(thisBox); // print all descending //{boxSerialNumber} //-- { boxItemName} – ${ boxItemPrice}: { boxItemQuantity} //-- ${ boxPrice} //format :f2 } } //---------------------------------------------------- //---------------------------------------------------- //---------------------------------------------------- // store the prices in temporary list List Prices = new List(); for (int i = 0; i < Boxes.Count; i++) { Prices.Add(Boxes[i].Item.Price); } double[] PricesArr = Prices.ToArray(); Array.Sort(PricesArr); bool Found = false; List BoxesArranged = new List(); int BoxesCount = Boxes.Count; while (true) { foreach (double d in PricesArr) { foreach (Box b in Boxes) { if (b.BoxPrice == d) { BoxesArranged.Add(b); Boxes.Remove(b); Found = true; break; } if (Found == true) { break; } } if (Found == true) { Found = false; break; } } if (BoxesArranged.Count == BoxesCount) { break; } } for (int i = 0; i < BoxesArranged.Count; i++) { Box b = BoxesArranged[i]; Console.WriteLine(b.SerialNumber); Console.WriteLine($"-- {b.Item.name} - ${b.Item.Price:f2}: {b.ItemQuantity}"); Console.WriteLine($"-- ${b.BoxPrice:f2}"); // box price } } } } public class Item { public string name { get; set; } public double Price { get; set; } } public class Box { public int SerialNumber { get; set; } public Item Item { get; set; } public int ItemQuantity { get; set; } public double BoxPrice { get; set; } } }