Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Last_Exe
- {
- class Client
- {
- public string Name { get; set; }
- public Dictionary<string, int> Order { get; set; }
- public decimal Bill { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, decimal> priceList = new Dictionary<string, decimal>(); // всички продукти и цени
- List<Client> clients = new List<Client>(); // всички клиенти + техните поръчки и сметка
- for (int i = 0; i < n; i++)
- {
- string[] beverige = Console.ReadLine().Split('-').ToArray();
- if (!priceList.ContainsKey(beverige[0]))
- {
- priceList.Add(beverige[0], decimal.Parse(beverige[1]));
- }
- priceList[beverige[0]] = decimal.Parse(beverige[1]);
- }
- string[] currentOrder = Console.ReadLine().Split(new char[] { '-', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- while (currentOrder[0] != "end")
- {
- string name = currentOrder[0];
- string product = currentOrder[1];
- int quantity = int.Parse(currentOrder[2]);
- Dictionary<string, int> current = new Dictionary<string, int>(); // текуща поръчка - продукт и брой
- if (priceList.ContainsKey(product)) // проверка дали продуктът съществува
- {
- var clientIneed = clients.FirstOrDefault(x => x.Name == name); // проверка дали клиентът съществува
- if (clientIneed == null)
- {
- var client = new Client();
- client.Name = name;
- current.Add(product, quantity);
- client.Order = current;
- foreach (var item in priceList.Where(x => x.Key == product))
- {
- client.Bill += quantity * item.Value;
- }
- clients.Add(client);
- }
- else
- {
- var productIneedKVP = clientIneed.Order.FirstOrDefault(x => x.Key == product); // проверка дали клиентът е поръчвал от същия продукт
- var productIneed = productIneedKVP.Key;
- if (productIneed == null)
- {
- clientIneed.Order.Add(product, quantity);
- foreach (var item in priceList.Where(x => x.Key == product))
- {
- clientIneed.Bill += quantity * item.Value;
- }
- }
- else
- {
- clientIneed.Order[productIneed] += quantity;
- foreach (var item in priceList.Where(x => x.Key == product))
- {
- clientIneed.Bill += quantity * item.Value;
- }
- }
- }
- }
- currentOrder = Console.ReadLine().Split(new char[] { '-', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- }
- decimal totalBill = 0;
- foreach (var item in clients.OrderBy(x => x.Name))
- {
- Console.WriteLine($"{item.Name}");
- foreach (var itemm in item.Order)
- {
- Console.WriteLine($"-- {itemm.Key} - { itemm.Value}");
- }
- Console.WriteLine($"Bill: {item.Bill:f2}");
- totalBill += item.Bill;
- }
- Console.WriteLine($"Total bill: {totalBill:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement