Guest User

Untitled

a guest
Oct 15th, 2016
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 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 Andrey_and_billiard
  8. {
  9. public class Customer
  10. {
  11. public string Name { get; set; }
  12. public Dictionary<string, decimal> PurchaseList { get; set; }
  13. public decimal Bill { get { return PurchaseList.Values.Sum(); } }
  14. }
  15. class Program
  16. {
  17. static void Main(string[] args)
  18. {
  19.  
  20. int entities = int.Parse(Console.ReadLine());
  21. Dictionary<string, decimal> priceList = new Dictionary<string, decimal>();
  22.  
  23. for (int i = 0; i < entities; i++)
  24. {
  25. string[] entityLine = Console.ReadLine().Split('-').ToArray();
  26. string item = entityLine[0];
  27. decimal itemPrice = decimal.Parse(entityLine[1]);
  28. priceList[item] = itemPrice;
  29. }
  30. List<Customer> customers = new List<Customer>();
  31. do
  32. {
  33. string input = Console.ReadLine();
  34.  
  35. if (input == "end of clients")
  36. {
  37. break;
  38. }
  39. string[] customerPurchaseLine = input.Split('-').ToArray();
  40. string customerName = customerPurchaseLine[0];
  41.  
  42. string product = customerPurchaseLine[1].Split(',')[0];
  43. int amounth = int.Parse(customerPurchaseLine[1].Split(',')[1]);
  44. Customer currentCustomer = new Customer();
  45. if (!priceList.ContainsKey(product))
  46. {
  47. continue;
  48. }
  49.  
  50. currentCustomer.Name = customerName;
  51. currentCustomer.PurchaseList = new Dictionary<string, decimal>();
  52. currentCustomer.PurchaseList[product] = amounth;
  53. bool exists = false;
  54.  
  55. foreach (var custName in customers)
  56. {
  57. if (custName.Name == currentCustomer.Name)
  58. {
  59. if (custName.PurchaseList.ContainsKey(product))
  60. {
  61. exists = true;
  62. custName.PurchaseList[product] += amounth;
  63. }
  64. else
  65. {
  66. custName.PurchaseList[product] = amounth;
  67. }
  68. }
  69. }
  70.  
  71. if (!exists)
  72. {
  73. customers.Add(currentCustomer);
  74. }
  75.  
  76. } while (true);
  77.  
  78. decimal totalBill = default(decimal);
  79.  
  80. foreach (var customer in customers.OrderBy(name => name.Name))
  81. {
  82.  
  83. Console.WriteLine($"{customer.Name}");
  84. foreach (var item in customer.PurchaseList)
  85. {
  86. Console.WriteLine($"-- {item.Key} - {item.Value}");
  87. Console.WriteLine("Bill: {0:0.00}", priceList[item.Key] * item.Value);
  88.  
  89. totalBill += priceList[item.Key] * item.Value;
  90. }
  91.  
  92. }
  93. Console.WriteLine("Total bill: {0:0.00}", totalBill);
  94.  
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment