Advertisement
penkafileva

07.Andrey_and_Billiard

Oct 15th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.17 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.     class Customer
  10.     {
  11.         public string Name { get; set; }
  12.         public Dictionary<string, double> ShopList { get; set; }
  13.         public double Bill { get; set; }
  14.     }
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             int count = int.Parse(Console.ReadLine());
  20.             Dictionary<string, double> productsPrice = new Dictionary<string, double>();
  21.             for (int i = 0; i < count; i++)
  22.             {
  23.                 var input = Console.ReadLine().Split('-');
  24.                 var product = input[0];
  25.                 var price = double.Parse(input[1]);
  26.                 if (!productsPrice.ContainsKey(product))
  27.                 {
  28.                     productsPrice[product] = 0;
  29.                 }
  30.                 productsPrice[product] = price;
  31.             }
  32.             var tokens = Console.ReadLine();
  33.             var shopList = new Dictionary<string, double>();
  34.             List<Customer> clients = new List<Customer>();
  35.             while (tokens != "end of clients")
  36.             {
  37.                 var token = tokens.Split('-', ',');
  38.                 var name = token[0];
  39.                 var prod = token[1];
  40.                 var quantity = double.Parse(token[2]);
  41.                 shopList = new Dictionary<string, double>();
  42.                 if (!productsPrice.ContainsKey(prod))
  43.                 {
  44.                     tokens = Console.ReadLine();
  45.                     continue;
  46.                    
  47.                 }
  48.                 if (clients.Any(a => a.Name == name))
  49.                 {
  50.                     Customer customer = clients.First(a => a.Name == name);
  51.                     if (!customer.ShopList.ContainsKey(prod))
  52.                     {
  53.                         customer.ShopList.Add(prod, quantity);
  54.                     }
  55.                     else
  56.                     {
  57.                         customer.ShopList[prod] += quantity;
  58.                     }
  59.                     customer.Bill += quantity * productsPrice[prod];
  60.                 }
  61.                 else
  62.                 {
  63.  
  64.                     Customer customer = new Customer();
  65.                     customer.Name = name;
  66.                     customer.ShopList = new Dictionary<string, double>();
  67.                     customer.ShopList.Add(prod, quantity);
  68.                     customer.Bill += (quantity * productsPrice[prod]);
  69.                     clients.Add(customer);
  70.                 }
  71.                
  72.                 tokens = Console.ReadLine();
  73.             }
  74.             double totalBills = 0.0;
  75.             foreach (Customer item in clients.OrderBy(a => a.Name))
  76.             {
  77.                 Console.WriteLine(item.Name);
  78.                 foreach (var it in item.ShopList)
  79.                 {
  80.                     Console.WriteLine($"-- {it.Key} - {it.Value}");
  81.                 }
  82.                 Console.WriteLine($"Bill: {item.Bill:f2}");
  83.                 totalBills = totalBills + item.Bill;
  84.             }
  85.             Console.WriteLine($"Total bill: {totalBills:f2}");
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement