Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _07.Andrey_and_Billiard
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, decimal> ShopInventory = new Dictionary<string, decimal>();
- for (int i = 0; i < n; i++)
- {
- string[] shopInfo = Console.ReadLine().Split('-');
- if (!ShopInventory.ContainsKey(shopInfo[0]))
- {
- ShopInventory.Add(shopInfo[0], decimal.Parse(shopInfo[1]));
- }
- else
- {
- ShopInventory[shopInfo[0]] = decimal.Parse(shopInfo[1]);
- }
- }
- string[] customerInfo = Console.ReadLine().Split('-', ',');
- List<Customer> clientList = new List<Customer>();
- while (customerInfo[0] != "end of clients")
- {
- Customer client = ReadCustomer(customerInfo);
- foreach (var item in ShopInventory)
- {
- foreach (var order in client.ShoppingList)
- {
- if (item.Key.Contains(order.Key))
- {
- client.Bill += order.Value * item.Value;
- clientList.Add(client);
- break;
- }
- }
- }
- customerInfo = Console.ReadLine().Split('-', ',');
- }
- decimal totalBill = 0;
- foreach (var person in clientList.OrderBy(x => x.Name))
- {
- Console.WriteLine($"{person.Name}");
- foreach (var order in person.ShoppingList)
- {
- Console.WriteLine($"-- {order.Key} - {order.Value}");
- }
- Console.WriteLine($"Bill: {person.Bill:F2}");
- totalBill += person.Bill;
- }
- Console.WriteLine($"Total bill: {totalBill:F2}");
- }
- static Customer ReadCustomer(string[] customerInfo)
- {
- Customer customer = new Customer();
- customer = new Customer
- {
- Name = customerInfo[0],
- ShoppingList = new Dictionary<string, int>
- {
- { customerInfo[1], int.Parse(customerInfo[2]) }
- }
- };
- return customer;
- }
- }
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> ShoppingList { get; set; }
- public decimal Bill { get; set; }
- }
- }
Add Comment
Please, Sign In to add comment