Guest User

Untitled

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