Advertisement
Stan0033

Untitled

Jun 29th, 2021
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. class main{
  11. public static void Main()
  12. {
  13. static string Get() { return Console.ReadLine(); }
  14.  
  15. List<Item> Items = new List<Item>();
  16. List<Box> Boxes = new List<Box>();
  17. while (true)
  18. {
  19. string command = Get();
  20. if (command == "end") { break; }
  21. else
  22. {
  23.  
  24. string[] data = command.Split(' ').ToArray();
  25. int this_SerialN = Convert.ToInt32(data[0]);
  26. int this_ItemQuantity = Convert.ToInt32(data[2]);
  27. double this_ItemPrice = double.Parse(data[3]);
  28. string this_ItemName = data[1];
  29. double this_PriceOfBox = this_ItemPrice * this_ItemQuantity;
  30. //------------------------------------------------
  31. Box thisBox = new Box();
  32. Item thisItem = new Item();
  33. //----------------------------------
  34. thisItem.name = this_ItemName;
  35. thisItem.Price = this_ItemPrice;
  36. thisBox.Item = thisItem;
  37. thisBox.SerialNumber = this_SerialN;
  38. thisBox.ItemQuantity = this_ItemQuantity;
  39. thisBox.BoxPrice = this_PriceOfBox;
  40. Items.Add(thisItem);
  41. Boxes.Add(thisBox);
  42. // print all descending
  43. //{boxSerialNumber}
  44. //-- { boxItemName} – ${ boxItemPrice}: { boxItemQuantity}
  45. //-- ${ boxPrice}
  46. //format :f2
  47. }
  48. }
  49.  
  50. //----------------------------------------------------
  51. //----------------------------------------------------
  52. //----------------------------------------------------
  53. // store the prices in temporary list
  54. List<double> Prices = new List<double>();
  55. for (int i = 0; i < Boxes.Count; i++)
  56. {
  57. Prices.Add(Boxes[i].Item.Price);
  58. }
  59. double[] PricesArr = Prices.ToArray();
  60. Array.Sort(PricesArr);
  61. bool Found = false;
  62. List<Box> BoxesArranged = new List<Box>();
  63. int BoxesCount = Boxes.Count;
  64. while (true)
  65. {
  66. foreach (double d in PricesArr)
  67. {
  68. foreach (Box b in Boxes)
  69. {
  70. if (b.BoxPrice == d)
  71. {
  72. BoxesArranged.Add(b);
  73. Boxes.Remove(b);
  74. Found = true;
  75. break;
  76. }
  77. if (Found == true) { break; }
  78. }
  79.  
  80. if (Found == true) { Found = false; break; }
  81.  
  82.  
  83. }
  84.  
  85. if (BoxesArranged.Count == BoxesCount) { break; }
  86. }
  87.  
  88. for (int i = 0; i < BoxesArranged.Count; i++)
  89. {
  90. Box b = BoxesArranged[i];
  91.  
  92. Console.WriteLine(b.SerialNumber);
  93. Console.WriteLine($"-- {b.Item.name} - ${b.Item.Price:f2}: {b.ItemQuantity}");
  94. Console.WriteLine($"-- ${b.BoxPrice:f2}"); // box price
  95.  
  96.  
  97.  
  98. }
  99.  
  100. }
  101. }
  102.  
  103.  
  104.  
  105.  
  106. }
  107. public class Item {
  108.  
  109. public string name { get; set; }
  110. public double Price { get; set; }
  111. }
  112. public class Box
  113. {
  114. public int SerialNumber { get; set; }
  115. public Item Item { get; set; }
  116. public int ItemQuantity { get; set; }
  117. public double BoxPrice { get; set; }
  118.  
  119. }
  120.  
  121. }
  122.  
  123.  
  124.  
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement