Advertisement
Guest User

07. AndreyAndBilliard

a guest
Oct 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07.AndreyAndBilliard
  6. {
  7. class Customer
  8. {
  9. public string Name { get; set; }
  10. public Dictionary<string, double> ShopList { get; set; }
  11. public double Bill { get; set; }
  12. }
  13.  
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. Dictionary<string, double> shop = new Dictionary<string, double>();
  19.  
  20. int amountEntities = int.Parse(Console.ReadLine());
  21. ReadShopSupply(shop, amountEntities);
  22.  
  23. List<Customer> listOfCustomers = new List<Customer>();
  24. double totalBill = ReadCustomersDesires(shop, listOfCustomers);
  25.  
  26. PrintResult(listOfCustomers, totalBill);
  27. }
  28.  
  29. private static void ReadShopSupply(Dictionary<string, double> shop, int amountEntities)
  30. {
  31. for (int i = 0; i < amountEntities; i++)
  32. {
  33. string[] input = Console.ReadLine().Split('-');
  34. string product = input[0];
  35. double priceProduct = double.Parse(input[1]);
  36. if (!shop.ContainsKey(product))
  37. {
  38. shop.Add(product, 0);
  39. }
  40. shop[product] = priceProduct;
  41. }
  42. }
  43.  
  44. private static double ReadCustomersDesires(Dictionary<string, double> shop, List<Customer> listOfCustomers)
  45. {
  46. double totalBill = 0;
  47.  
  48. while (true)
  49. {
  50. Customer newCustomer = new Customer();
  51. string input = Console.ReadLine();
  52. if (input == "end of clients") break;
  53. var input1 = input.Split(',', '-').ToArray();
  54. string name = input1[0];
  55. string wantedProduct = input1[1];
  56. double wantedQuantity = double.Parse(input1[2]);
  57.  
  58. if (!shop.ContainsKey(wantedProduct)) continue;
  59.  
  60. else
  61. {
  62. newCustomer.Name = name;
  63. newCustomer.ShopList = new Dictionary<string, double>();
  64. newCustomer.ShopList.Add(wantedProduct, wantedQuantity);
  65. newCustomer.Bill += wantedQuantity * shop[wantedProduct];
  66. totalBill += wantedQuantity * shop[wantedProduct];
  67. listOfCustomers.Add(newCustomer);
  68. }
  69. }
  70. return totalBill;
  71. }
  72.  
  73. private static void PrintResult(List<Customer> listOfCustomers, double totalBill)
  74. {
  75. var result = listOfCustomers.OrderBy(x => x.Name);
  76. foreach (var customer in result)
  77. {
  78. Console.WriteLine($"{customer.Name}");
  79. foreach (KeyValuePair<string, double> item in customer.ShopList)
  80. {
  81. Console.WriteLine($"-- {item.Key} - {item.Value}");
  82. }
  83. Console.WriteLine($"Bill: {customer.Bill:f2}");
  84. }
  85. Console.WriteLine($"Total bill: {totalBill:f2}");
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement