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 Andrey_and_billiard
- {
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> order { get; set; }
- public decimal Bill { get; set; }
- }
- class Program
- {
- static void InsertProductAndPrice(Dictionary<string, decimal> menu, string product, decimal price)
- {
- if (!menu.ContainsKey(product))
- {
- menu.Add(product, price);
- }
- else
- {
- menu[product] = price;
- }
- }
- static void Main()
- {
- Dictionary<string, decimal> menu = new Dictionary<string, decimal>();
- List<Customer> customers = new List<Customer>();
- int number = int.Parse(Console.ReadLine());
- for (int i = 0; i < number; i++)
- {
- string input = Console.ReadLine();
- string[] inputArr = input.Trim().Split('-');
- string product = inputArr[0];
- decimal price = decimal.Parse(inputArr[1]);
- InsertProductAndPrice(menu, product, price);
- }
- string inputOrder = null;
- do
- {
- inputOrder = Console.ReadLine();
- if (inputOrder=="end of clients")
- {
- break;
- }
- string[] inputOrderArr = inputOrder
- .Trim()
- .Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
- string namePerson = inputOrderArr[0];
- string productOrder = inputOrderArr[1];
- int quantity = int.Parse(inputOrderArr[2]);
- if (!menu.ContainsKey(productOrder))
- {
- continue;
- }
- if (!customers.Any(name => name.Name == namePerson))
- {
- Customer cust = new Customer();
- cust.order = new Dictionary<string, int>();
- cust.Name = namePerson;
- cust.order.Add(productOrder, quantity);
- cust.Bill += quantity * menu[productOrder];
- customers.Add(cust);
- }
- else
- {
- int index = customers.FindIndex(x => x.Name == namePerson);
- if (!customers[index].order.ContainsKey(productOrder))
- {
- customers[index].order.Add(productOrder, 0);
- }
- customers[index].order[productOrder] += quantity;
- customers[index].Bill += quantity * menu[productOrder];
- }
- } while (inputOrder != "end of clients");
- var sortCustomers = customers.OrderBy(x => x.Name).ToList();
- foreach (var custS in sortCustomers)
- {
- Console.WriteLine(custS.Name);
- foreach (KeyValuePair<string,int> kvp in custS.order)
- {
- Console.WriteLine("-- {0} - {1}",kvp.Key,kvp.Value);
- }
- Console.WriteLine("Bill: {0:F2}",custS.Bill);
- }
- Console.WriteLine("Total bill: {0}",sortCustomers.Sum(x => x.Bill));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement