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;
- class Customer
- {
- public string Name { get; set; }
- public SortedDictionary<string, double> ShopList { get; set; }
- public double Bill { get; set; }
- }
- class AndreyAndBilliard
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<string> namesList = new List<string>(); // това не е нужно
- List<Customer> customers = new List<Customer>();
- double totalBill = 0;
- Dictionary<string, double> productPrice = new Dictionary<string, double>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split('-');
- string product = input[0];
- double price = double.Parse(input[1]);
- if (!productPrice.ContainsKey(product))
- {
- productPrice.Add(product, 0);
- }
- productPrice[product] = price;
- }
- string inputCustomerss = Console.ReadLine();
- while (inputCustomerss != "end of clients")
- {
- string[] inputCustomers = inputCustomerss.Split('-', ',');
- if (!productPrice.ContainsKey(inputCustomers[1])) { inputCustomerss = Console.ReadLine(); continue; }
- Customer c1 = new Customer(); //Customer.ReadCustomer(inputCustomers);
- string customerName = inputCustomers[0];
- c1.Name = customerName;
- string product = inputCustomers[1];
- double quantity = double.Parse(inputCustomers[2]);
- c1.ShopList = new SortedDictionary<string, double>();
- c1.ShopList.Add(product, quantity);
- if (customers.Any(c => c.Name == customerName))
- {
- Customer existingCustomer = customers.First(c => c.Name == customerName);
- if (existingCustomer.ShopList.ContainsKey(product))
- {
- existingCustomer.ShopList[product] += quantity;
- } else
- {
- existingCustomer.ShopList[product] = quantity;
- }
- }
- else
- {
- customers.Add(c1);
- }
- if (!namesList.Contains(inputCustomers[0])) { namesList.Add(inputCustomers[0]); } // това не е нужно
- inputCustomerss = Console.ReadLine();
- }
- foreach (var customer in customers)
- {
- customer.Bill = 0;
- foreach (var item in customer.ShopList)
- {
- // debug:
- //Console.WriteLine(item.Key);
- //Console.WriteLine(item.Value);
- foreach (var product in productPrice)
- {
- if (item.Key == product.Key)
- {
- customer.Bill += item.Value * product.Value;
- }
- }
- }
- }
- customers.OrderBy(x => x.Name);
- foreach (var customer in customers.OrderBy(x => x.Name))
- {
- // Console.WriteLine("CustomerName :{0}", customer.Name);
- Console.WriteLine(customer.Name);
- foreach (var item in customer.ShopList)
- {
- //Console.WriteLine("Product :{0}", item.Key);
- //Console.WriteLine("Quantity :{0}", item.Value);
- Console.WriteLine($"-- {item.Key} - {item.Value}");
- }
- //Console.WriteLine("Bill :{0}", customer.Bill);
- Console.WriteLine("Bill: {0:F2}", customer.Bill);
- }
- Console.WriteLine("Total bill: {0:F2}", customers.Sum(c => c.Bill));
- }// end of main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement