Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace StoreBoxes
- {
- class Item
- {
- public string Name { get; set; }
- public double Price { get; set; }
- static void Main(string[] args)
- {
- List<Item> item = new List<Item>();
- List<Box> box = new List<Box>();
- List <string> input = Console.ReadLine().Split().ToList();
- while ( input[0] != "end")
- {
- Item currentItem = new Item();
- Box currentBox = new Box();
- int serial = int.Parse(input[0]);
- string name = input[1];
- int quantity = int.Parse(input[2]);
- double price = double.Parse(input[3]);
- currentItem.Name = name;
- currentItem.Price = price;
- item.Add(currentItem);
- currentBox.SerialNumber = serial;
- currentBox.ItemName = name;
- currentBox.Quantity = quantity;
- currentBox.SumBox = (decimal)(quantity * price);
- box.Add(currentBox);
- input = Console.ReadLine().Split().ToList();
- }
- for (int i = 0; i < box.Count; i++)
- {
- for (int j = i; j < box.Count; j++)
- {
- if (box[j].SumBox < box[i].SumBox)
- {
- Box current = box[j];
- Item temp = item[j];
- box[j] = box[i];
- box[i] = current;
- item[j] = item[i];
- item[i] = temp;
- }
- }
- }
- box.Reverse();
- item.Reverse();
- for (int i = 0; i < box.Count; i++)
- {
- Console.WriteLine($"{box[i].SerialNumber}");
- Console.WriteLine($"-- { box[i].ItemName} - ${item[i].Price:F2}: { box[i].Quantity}");
- Console.WriteLine($"-- ${box[i].Quantity * item[i].Price:F2}");
- }
- }
- }
- class Box
- {
- public int SerialNumber { get; set; }
- public string ItemName { get; set; }
- public double Quantity { get; set; }
- public decimal SumBox { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement