Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _07.AndreyAndBilliard
- {
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, double> ShopList { get; set; }
- public double Bill { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, double> shop = new Dictionary<string, double>();
- int amountEntities = int.Parse(Console.ReadLine());
- ReadShopSupply(shop, amountEntities);
- List<Customer> listOfCustomers = new List<Customer>();
- double totalBill = ReadCustomersDesires(shop, listOfCustomers);
- PrintResult(listOfCustomers, totalBill);
- }
- private static void ReadShopSupply(Dictionary<string, double> shop, int amountEntities)
- {
- for (int i = 0; i < amountEntities; i++)
- {
- string[] input = Console.ReadLine().Split('-');
- string product = input[0];
- double priceProduct = double.Parse(input[1]);
- if (!shop.ContainsKey(product))
- {
- shop.Add(product, 0);
- }
- shop[product] = priceProduct;
- }
- }
- private static double ReadCustomersDesires(Dictionary<string, double> shop, List<Customer> listOfCustomers)
- {
- double totalBill = 0;
- while (true)
- {
- Customer newCustomer = new Customer();
- string input = Console.ReadLine();
- if (input == "end of clients") break;
- var input1 = input.Split(',', '-').ToArray();
- string name = input1[0];
- string wantedProduct = input1[1];
- double wantedQuantity = double.Parse(input1[2]);
- if (!shop.ContainsKey(wantedProduct)) continue;
- else
- {
- newCustomer.Name = name;
- newCustomer.ShopList = new Dictionary<string, double>();
- newCustomer.ShopList.Add(wantedProduct, wantedQuantity);
- newCustomer.Bill += wantedQuantity * shop[wantedProduct];
- totalBill += wantedQuantity * shop[wantedProduct];
- listOfCustomers.Add(newCustomer);
- }
- }
- return totalBill;
- }
- private static void PrintResult(List<Customer> listOfCustomers, double totalBill)
- {
- var result = listOfCustomers.OrderBy(x => x.Name);
- foreach (var customer in result)
- {
- Console.WriteLine($"{customer.Name}");
- foreach (KeyValuePair<string, double> item in customer.ShopList)
- {
- Console.WriteLine($"-- {item.Key} - {item.Value}");
- }
- Console.WriteLine($"Bill: {customer.Bill:f2}");
- }
- Console.WriteLine($"Total bill: {totalBill:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement