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;
- namespace _7.Andrey_and_billiard
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var productPrice = new Dictionary<string, decimal>();
- for (int i = 0; i < n; i++)
- {
- var currentText = Console.ReadLine().Split('-').ToArray();
- productPrice[currentText[0]] = decimal.Parse(currentText[1]);
- }
- string input = Console.ReadLine();
- var listCustemers = new List<Customer>();
- while (!input.Equals("end of clients"))
- {
- var splitedInput = input.Split('-', ',').ToArray();
- string custemerName = splitedInput[0];
- string product = splitedInput[1];
- int quantity = int.Parse(splitedInput[2]);
- if (productPrice.ContainsKey(product))
- {
- if (listCustemers.Any(x => x.name == custemerName))
- {
- Customer customer = listCustemers.First(x => x.name == custemerName);
- if (listCustemers.Any(x=>x.productQnty.ContainsKey(product)))
- {
- customer.productQnty[product] += quantity;
- customer.personalBill += quantity * productPrice[product];
- }
- else
- {
- customer.productQnty.Add(product,quantity);
- customer.personalBill += quantity * productPrice[product];
- }
- }
- else
- {
- Customer currentCustomer = new Customer();
- currentCustomer.name = custemerName;
- currentCustomer.productQnty = new Dictionary<string, int>();
- currentCustomer.productQnty.Add(product, quantity);
- currentCustomer.personalBill= quantity * productPrice[product];
- listCustemers.Add(currentCustomer);
- }
- }
- input = Console.ReadLine();
- }
- foreach (var item in listCustemers.OrderBy(x=>x.name))
- {
- Console.WriteLine(item.name);
- foreach (var customerProductQuantity in item.productQnty)
- {
- Console.WriteLine("-- {0} - {1}",customerProductQuantity.Key,customerProductQuantity.Value);
- }
- Console.WriteLine("Bill: {0:f2}",item.personalBill);
- }
- decimal counter = 0;
- foreach (var item in listCustemers)
- {
- counter += item.personalBill;
- }
- Console.WriteLine("Total bill: {0}",counter);
- }
- }
- public class Customer
- {
- public string name { get; set; }
- public Dictionary<string, int> productQnty { get; set; }
- public decimal personalBill { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement