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 Program
- {
- static void Main(string[] args)
- {
- int num = int.Parse(Console.ReadLine());
- var entities = new Dictionary<string, decimal>();
- for (int i = 0; i < num; i++)
- {
- string[] cmds = Console.ReadLine().Split('-').ToArray();
- string product = cmds[0];
- decimal price = decimal.Parse(cmds[1]);
- if (!entities.ContainsKey(product))
- {
- entities.Add(product, 0);
- }
- entities[product] = price;
- }
- string commands = Console.ReadLine();
- List<Customer> customer = new List<Customer>();
- while (commands != "end of clients")
- {
- Customer custom = new Customer();
- var dict = new Dictionary<string, int>();
- string[] input = commands.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
- string name = input[0];
- string product = input[1];
- int quantity = int.Parse(input[2]);
- if (!entities.ContainsKey(product))
- {
- }
- else
- {
- bool getIn = true;
- foreach (var student in customer.Where(x=> x.Name==name))
- {
- if (!student.ShopList.ContainsKey(product))
- {
- student.ShopList.Add(product, 0);
- }
- student.ShopList[product] += quantity;
- getIn = false;
- }
- if (getIn)
- {
- custom.Name = name;
- dict.Add(product, quantity);
- custom.ShopList = dict;
- customer.Add(custom);
- }
- }
- commands = Console.ReadLine();
- }
- decimal totalBill = 0m;
- foreach (var student in customer.OrderBy(x => x.Name))
- {
- Console.WriteLine(student.Name);
- foreach (var kvp in student.ShopList)
- {
- Console.WriteLine($"-- {kvp.Key} - {kvp.Value}");
- foreach (var entity in entities)
- {
- if (kvp.Key == entity.Key)
- {
- decimal bill = bill = kvp.Value * entity.Value;
- Console.WriteLine($"Bill: {bill:F2}");
- totalBill += bill;
- }
- }
- }
- }
- Console.WriteLine($"Total bill: {totalBill:F2}");
- }
- }
- class Customer
- {
- public string Name { get; set; }
- public Dictionary<string, int> ShopList { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement