Advertisement
Guest User

07.Andrey and Billiard

a guest
Feb 10th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _07.Andrey_and_Billiard
  8. {
  9.     public class AndreyAndBilliard
  10.     {
  11.         public static void Main()
  12.         {
  13.             var n = int.Parse(Console.ReadLine());
  14.             var ProductsPrice = new Dictionary<string, double>();
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 var product = Console.ReadLine()
  18.                     .Split('-')
  19.                     .ToList();
  20.                 ProductsPrice[product[0]] = double.Parse(product[1]);
  21.             }
  22.             var billByPerson = new SortedDictionary<string, Dictionary<string, double>>();
  23.             var personOrder = Console.ReadLine().Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
  24.             var totalBill = 0.0;
  25.             while (personOrder[0] != "end of clients")
  26.             {
  27.                 var quantity = double.Parse(personOrder[2]);
  28.                 if (ProductsPrice.ContainsKey(personOrder[1]))
  29.                 {
  30.                     if (billByPerson.ContainsKey(personOrder[0]))
  31.                     {
  32.                         if (billByPerson[personOrder[0]].ContainsKey(personOrder[1]))
  33.                         {
  34.                             billByPerson[personOrder[0]][personOrder[1]] += quantity * ProductsPrice[personOrder[1]];
  35.                         }else
  36.                         {
  37.                             billByPerson[personOrder[0]][personOrder[1]] = quantity * ProductsPrice[personOrder[1]];
  38.                         }
  39.                         totalBill += billByPerson[personOrder[0]][personOrder[1]];
  40.                     }else
  41.                     {
  42.                         billByPerson.Add(personOrder[0], new Dictionary<string, double>());
  43.                         billByPerson[personOrder[0]][personOrder[1]] = quantity * ProductsPrice[personOrder[1]];
  44.                         totalBill += billByPerson[personOrder[0]][personOrder[1]];
  45.                     }
  46.  
  47.                 }
  48.                 personOrder = Console.ReadLine().Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
  49.             }
  50.             var finalBill = 0.0;
  51.             foreach (var person in billByPerson)
  52.             {
  53.                 Console.WriteLine(person.Key);
  54.                 var personalBill = 0.0;
  55.                 foreach (var bill in person.Value)
  56.                 {
  57.                     Console.WriteLine($"-- {bill.Key} - {bill.Value / ProductsPrice[bill.Key]}");
  58.                     personalBill += bill.Value;
  59.                     finalBill += bill.Value;
  60.                 }
  61.                 Console.WriteLine($"Bill: {personalBill:f2}");
  62.             }
  63.             Console.WriteLine($"Total bill: {finalBill:f2}");
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement