Advertisement
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;
- using System.Globalization;
- using System.Threading;
- namespace AndreyAndBilliard
- {
- class Program
- {
- private static void AddProducts(Dictionary<string, decimal> products, int number)
- {
- for (int i = 0; i < number; i++)
- {
- string[] input = Console.ReadLine().Split('-')
- .ToArray();
- string productName = input[0];
- decimal price = decimal.Parse(input[1]);
- if (products.ContainsKey(productName))
- {
- products[productName] = price;
- }
- else
- {
- products.Add(productName, price);
- }
- }
- }
- private static void AddCustomers(List<Customer> customers, Dictionary<string, decimal> products)
- {
- string input = Console.ReadLine();
- int customerIndexCounter = 0;
- while (input != "end of clients")
- {
- string[] custInfo = input.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string name = custInfo[0];
- string product = custInfo[1];
- int quantity = int.Parse(custInfo[2]);
- if (products.ContainsKey(product))
- {
- decimal productPrice = products[product];
- if (customers.Select(x => x.Name).Contains(name))
- {
- foreach (var customer in customers.Where(x => x.Name == name))
- {
- if (customer.ShopList.ContainsKey(product))
- {
- customer.ShopList[product] += quantity;
- }else
- {
- customer.ShopList.Add(product, quantity);
- customer.Bill += quantity * productPrice;
- }
- }
- }
- else
- {
- customers.Add(new Customer
- {
- Name = name,
- ShopList = new Dictionary<string, int>()
- });
- customers[customerIndexCounter].ShopList.Add(product, quantity);
- customers[customerIndexCounter].Bill += quantity * productPrice;
- customerIndexCounter++;
- }
- }
- input = Console.ReadLine();
- }
- }
- private static void PrintCustomers(List<Customer> customers)
- {
- decimal totalBill = 0;
- foreach (var customer in customers.OrderBy(x => x.Name))
- {
- Console.WriteLine("{0}", customer.Name);
- foreach (var item in customer.ShopList)
- {
- Console.WriteLine("-- {0} - {1}", item.Key, item.Value);
- }
- Console.WriteLine("Bill: {0:F2}", customer.Bill);
- totalBill += customer.Bill;
- }
- Console.WriteLine("Total bill: {0:F2}", totalBill);
- }
- static void Main(string[] args)
- {
- Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
- int numOfProducts = int.Parse(Console.ReadLine());
- var products = new Dictionary<string, decimal>();
- List<Customer> customers = new List<Customer>();
- AddProducts(products, numOfProducts);
- AddCustomers(customers, products);
- PrintCustomers(customers);
- }
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> ShopList { get; set; }
- public decimal Bill { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement