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 AndreyAndbilliard
- {
- class Program
- {
- static void Main(string[] args)
- {
- int productsCount = int.Parse(Console.ReadLine());
- Dictionary<string, decimal> shopProducts = new Dictionary<string, decimal>();
- //adding products to shop
- for (int i = 0; i < productsCount; i++)
- {
- string[] tokens = Console.ReadLine().Split('-').ToArray();
- string name = tokens.First();
- decimal price = decimal.Parse(tokens[1]);
- if (shopProducts.ContainsKey(tokens.First()))
- {
- shopProducts[name] = price;
- }
- else
- {
- shopProducts.Add(tokens.First(), tokens.Skip(1).Select(decimal.Parse).First());
- }
- }
- List<Customer> allCustomers = new List<Customer>();
- while (true)
- {
- string[] tokens = Console.ReadLine().Split('-', ',').ToArray();
- string name = tokens[0];
- if (name == "end of clients")
- {
- break;
- }
- string product = tokens[1];
- if (shopProducts.ContainsKey(product))
- {
- int quantity = int.Parse(tokens[2]);
- decimal price = shopProducts[product];
- Customer customer = new Customer()
- {
- Name = name,
- ItemsInfo = new Dictionary<string, int>()
- {
- {product, quantity}
- },
- Bill = price * quantity
- };
- allCustomers.Add(customer);
- }
- else
- {
- continue;
- }
- }
- var names = allCustomers.Select(a => a.Name).Distinct().ToList();
- var customerInfo = new List<CustomerInfo>();
- foreach (var name in names)
- {
- var products = allCustomers.Where(a => a.Name == name).Select(a => a.ItemsInfo).ToList();
- var bill = allCustomers.Where(a => a.Name == name).Sum(a => a.Bill);
- customerInfo.Add(new CustomerInfo()
- {
- Name = name,
- Products = products,
- Bill = bill
- });
- }
- decimal totalBill = 0;
- customerInfo = customerInfo.OrderBy(a => a.Name).ToList();
- foreach (var customer in customerInfo)
- {
- Console.WriteLine(customer.Name);
- foreach (var item in customer.Products)
- {
- foreach (var product in item)
- {
- Console.WriteLine($"-- {product.Key} - {product.Value}");
- }
- }
- Console.WriteLine($"Bill: {customer.Bill:F2}");
- totalBill += customer.Bill;
- }
- Console.WriteLine("Total bill: {0}", totalBill);
- }
- }
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> ItemsInfo { get; set; }
- public decimal Bill { get; set; }
- }
- class CustomerInfo
- {
- public string Name { get; set; }
- public List<Dictionary<string, int>> Products { get; set; }
- public decimal Bill { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment