MilenaPetkanova

AndreyAndBilliard

Oct 21st, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Customer
  6. {
  7. public string Name { get; set; }
  8. public Dictionary<string, int> ProductQuantity { get; set; }
  9. public decimal Bill { get; set; }
  10. }
  11.  
  12. class AndreyAndBilliard
  13. {
  14. static void Main()
  15. {
  16. var entities = new Dictionary<string, decimal>();
  17.  
  18. int entitiesCount = int.Parse(Console.ReadLine());
  19.  
  20. for (int i = 0; i < entitiesCount; i++)
  21. {
  22. var newEntity = Console.ReadLine().Split('-').ToArray();
  23. string entityName = newEntity[0];
  24. decimal entityPrise = decimal.Parse(newEntity[1]);
  25.  
  26. if (!entities.ContainsKey(entityName))
  27. {
  28. entities.Add(entityName, entityPrise);
  29. }
  30. else
  31. {
  32. entities[entityName] = entityPrise;
  33. }
  34. }
  35.  
  36. List<Customer> allCustomers = new List<Customer>();
  37.  
  38. string command = Console.ReadLine();
  39. while (command != "end of clients")
  40. {
  41. string[] commandArgs = command.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
  42.  
  43. if (entities.ContainsKey(commandArgs[1]))
  44. {
  45. string product = commandArgs[1];
  46. int quantity = int.Parse(commandArgs[2]);
  47. decimal spent = decimal.Parse(commandArgs[2]) * entities[commandArgs[1]];
  48.  
  49. Customer currentCustomer = new Customer();
  50. currentCustomer.Name = commandArgs[0];
  51. currentCustomer.ProductQuantity = new Dictionary<string, int>();
  52. currentCustomer.ProductQuantity.Add(product, quantity);
  53. currentCustomer.Bill = spent;
  54.  
  55. allCustomers.Add(currentCustomer);
  56. }
  57.  
  58. command = Console.ReadLine();
  59. }
  60.  
  61. decimal totalBill = 0;
  62. foreach (var customer in allCustomers.OrderBy(x => x.Name))
  63. {
  64. Console.WriteLine(customer.Name);
  65. foreach (var product in customer.ProductQuantity)
  66. {
  67. Console.WriteLine("-- {0} - {1}",
  68. product.Key, product.Value);
  69. }
  70. Console.WriteLine("Bill: {0:f2}", customer.Bill);
  71. totalBill += customer.Bill;
  72. }
  73. Console.WriteLine("Total bill: {0:f2}", totalBill);
  74. }
  75. }
Add Comment
Please, Sign In to add comment