Advertisement
EmoRz

07. Andrey and Billiard

Jun 12th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AndreyBilliard
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var amount = int.Parse(Console.ReadLine());
  12.  
  13.             Dictionary<string, double> priceList = new Dictionary<string, double>();
  14.             for (int i = 0; i < amount; i++)
  15.             {
  16.                 string[] input = Console.ReadLine().Split(new char[] { '-'});
  17.                 var typeProduct = input[0];
  18.                 var price = Math.Round(double.Parse(input[1]), 2);
  19.                 if (!priceList.ContainsKey(typeProduct))
  20.                 {
  21.                     priceList.Add(typeProduct, 0.0);
  22.                 }
  23.                 priceList[typeProduct] = price;
  24.             }
  25.             var clientInput = Console.ReadLine();
  26.             Dictionary<string, Dictionary<string, double>> clientData = new Dictionary<string, Dictionary<string, double>>();
  27.             while (clientInput != "end of clients")
  28.             {
  29.                 string[] clients = clientInput.Split(new char[] {'-', ',' });
  30.                 var nameOfClient = clients[0];
  31.                 var clientsProduct = clients[1];
  32.                 var quantity = Math.Round(double.Parse(clients[2]), 2);
  33.                 if (priceList.ContainsKey(clientsProduct))
  34.                 {
  35.                     if (!clientData.ContainsKey(nameOfClient))
  36.                     {
  37.                         clientData.Add(nameOfClient, new Dictionary<string, double>() );
  38.                     }
  39.                     if (!clientData[nameOfClient].ContainsKey(clientsProduct))
  40.                     {
  41.                         clientData[nameOfClient].Add(clientsProduct, 0.0);
  42.                     }
  43.                     clientData[nameOfClient][clientsProduct] += quantity;
  44.                 }
  45.                 clientInput = Console.ReadLine();
  46.             }
  47.             decimal totalBill = 0m;
  48.             foreach (var item in clientData.OrderBy(x => x.Key))
  49.             {
  50.                 Console.WriteLine(item.Key);
  51.                 var bill = 0.0;
  52.                 foreach (var i in item.Value)
  53.                 {
  54.                     Console.WriteLine($"-- {i.Key} - {i.Value}");
  55.                     foreach (var qu in priceList)
  56.                     {
  57.                         if (qu.Key == i.Key)
  58.                         {
  59.                             bill += qu.Value * i.Value;
  60.                         }
  61.                     }
  62.  
  63.                 }
  64.                 Console.WriteLine($"Bill: {bill:f2}");
  65.                 totalBill += (decimal)bill;
  66.  
  67.             }
  68.             Console.WriteLine($"Total bill: {totalBill:f2}");
  69.         }
  70.        
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement