Advertisement
Gesh4o

Untitled

Oct 12th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 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. class Customer
  8. {
  9. public string Name { get; set; }
  10. public SortedDictionary<string, double> ShopList { get; set; }
  11. public double Bill { get; set; }
  12. }
  13.  
  14. class AndreyAndBilliard
  15. {
  16. static void Main(string[] args)
  17. {
  18. int n = int.Parse(Console.ReadLine());
  19. List<string> namesList = new List<string>(); // това не е нужно
  20. List<Customer> customers = new List<Customer>();
  21. double totalBill = 0;
  22.  
  23. Dictionary<string, double> productPrice = new Dictionary<string, double>();
  24. for (int i = 0; i < n; i++)
  25. {
  26. string[] input = Console.ReadLine().Split('-');
  27. string product = input[0];
  28. double price = double.Parse(input[1]);
  29. if (!productPrice.ContainsKey(product))
  30. {
  31. productPrice.Add(product, 0);
  32. }
  33. productPrice[product] = price;
  34. }
  35.  
  36. string inputCustomerss = Console.ReadLine();
  37.  
  38. while (inputCustomerss != "end of clients")
  39. {
  40. string[] inputCustomers = inputCustomerss.Split('-', ',');
  41. if (!productPrice.ContainsKey(inputCustomers[1])) { inputCustomerss = Console.ReadLine(); continue; }
  42. Customer c1 = new Customer(); //Customer.ReadCustomer(inputCustomers);
  43. string customerName = inputCustomers[0];
  44. c1.Name = customerName;
  45. string product = inputCustomers[1];
  46. double quantity = double.Parse(inputCustomers[2]);
  47. c1.ShopList = new SortedDictionary<string, double>();
  48. c1.ShopList.Add(product, quantity);
  49.  
  50. if (customers.Any(c => c.Name == customerName))
  51. {
  52. Customer existingCustomer = customers.First(c => c.Name == customerName);
  53. if (existingCustomer.ShopList.ContainsKey(product))
  54. {
  55. existingCustomer.ShopList[product] += quantity;
  56. } else
  57. {
  58. existingCustomer.ShopList[product] = quantity;
  59.  
  60. }
  61. }
  62. else
  63. {
  64. customers.Add(c1);
  65. }
  66.  
  67. if (!namesList.Contains(inputCustomers[0])) { namesList.Add(inputCustomers[0]); } // това не е нужно
  68.  
  69.  
  70.  
  71.  
  72. inputCustomerss = Console.ReadLine();
  73. }
  74. foreach (var customer in customers)
  75. {
  76. customer.Bill = 0;
  77. foreach (var item in customer.ShopList)
  78. {
  79. // debug:
  80. //Console.WriteLine(item.Key);
  81. //Console.WriteLine(item.Value);
  82. foreach (var product in productPrice)
  83. {
  84. if (item.Key == product.Key)
  85. {
  86. customer.Bill += item.Value * product.Value;
  87. }
  88. }
  89. }
  90. }
  91. customers.OrderBy(x => x.Name);
  92. foreach (var customer in customers.OrderBy(x => x.Name))
  93. {
  94. // Console.WriteLine("CustomerName :{0}", customer.Name);
  95. Console.WriteLine(customer.Name);
  96. foreach (var item in customer.ShopList)
  97. {
  98. //Console.WriteLine("Product :{0}", item.Key);
  99. //Console.WriteLine("Quantity :{0}", item.Value);
  100. Console.WriteLine($"-- {item.Key} - {item.Value}");
  101. }
  102. //Console.WriteLine("Bill :{0}", customer.Bill);
  103. Console.WriteLine("Bill: {0:F2}", customer.Bill);
  104. }
  105. Console.WriteLine("Total bill: {0:F2}", customers.Sum(c => c.Bill));
  106.  
  107. }// end of main
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement