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
- {
- public class Program
- {
- public static void Main()
- {
- var numberOfEntities = int.Parse(Console.ReadLine());
- Dictionary<string, decimal> ProductsAndItsPrice = new Dictionary<string, decimal>();
- for (int i = 0; i < numberOfEntities; i++)
- {
- var productAndItsPrice = Console.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
- var product = productAndItsPrice[0];
- var price = decimal.Parse(productAndItsPrice[1]);
- //If the product thoes not exist, its added to dict with its price
- if (!ProductsAndItsPrice.ContainsKey(product))
- {
- ProductsAndItsPrice[product] = price;
- }
- //if the product exist it overwrite the price of the product
- else
- {
- ProductsAndItsPrice[product] = price;
- }
- }
- var order = Console.ReadLine();
- var listOfClients = new List<Customer>();
- while (order != "end of clients")
- {
- var result = order.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- var product = result[1];
- var quantity = int.Parse(result[2]);
- var name = result[0];
- // if the product that the client wants exist in the shop, creates new object(client)
- if (ProductsAndItsPrice.ContainsKey(product))
- {
- var client = new Customer();
- client.Name = name;
- client.Product = product;
- client.Quantity = quantity;
- client.Bill = client.Quantity * ProductsAndItsPrice[product];
- listOfClients.Add(client);
- }
- order = Console.ReadLine();
- }
- var clientSBill = new Dictionary<string, Dictionary<Object, decimal>>();
- foreach (var client in listOfClients)
- {
- if (!clientSBill.ContainsKey(client.Name))
- {
- clientSBill.Add(client.Name, new Dictionary<Object, decimal>());
- clientSBill[client.Name].Add(client, client.Bill);
- }
- else
- {
- if (!clientSBill[client.Name].ContainsKey(client.Product))
- {
- clientSBill[client.Name][client.Product] = client.Bill;
- clientSBill[client.Name][client.Quantity] = client.Quantity;
- }
- else
- {
- clientSBill[client.Name][client] += client.Bill;
- clientSBill[client.Name][client.Quantity] += client.Quantity;
- }
- }
- }
- }
- }
- }
- public class Customer
- {
- public decimal Bill { get; set; }
- public string Name { get; set; }
- public string Product { get; set; }
- public int Quantity { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement