Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Globalization;
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, decimal> products = GetProducts(n);
- SortedDictionary<string, Dictionary<string, int>> customers = new SortedDictionary<string, Dictionary<string, int>>();
- string[] input = Console.ReadLine().Split('-', ',').ToArray();
- while (input[0] != "end of clients")
- {
- Dictionary<string, int> temp = new Dictionary<string, int>();
- temp.Add(input[1], int.Parse(input[2]));
- string customer = input[0];
- string product = input[1];
- int quantity = int.Parse(input[2]);
- if (customers.ContainsKey(customer) && products.ContainsKey(product))
- {
- if (customers[customer].ContainsKey(product))
- {
- customers[customer][product] += quantity;
- }
- else
- {
- customers[customer].Add(product, quantity);
- }
- }
- else if (products.ContainsKey(product))
- {
- customers.Add(input[0], temp);
- }
- input = Console.ReadLine().Split('-', ',').ToArray();
- }
- decimal totalBill = 0;
- foreach (var customer in customers)
- {
- decimal bill = 0;
- Console.WriteLine(customer.Key);
- foreach (var pair in customers[customer.Key])
- {
- Console.WriteLine($"-- {pair.Key} - {pair.Value}");
- bill += pair.Value * products[pair.Key];
- }
- Console.WriteLine($"Bill: {bill:f2}");
- totalBill += bill;
- }
- Console.WriteLine($"Total bill: {totalBill:f2}");
- }
- static Dictionary<string, decimal> GetProducts(int n)
- {
- Dictionary<string, decimal> products = new Dictionary<string, decimal>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split('-').ToArray();
- if (products.ContainsKey(input[0]))
- {
- products[input[0]] = decimal.Parse(input[1]);
- }
- else
- {
- products.Add(input[0], decimal.Parse(input[1]));
- }
- }
- return products;
- }
- }
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> Bought { get; set; }
- public decimal Bill { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment