Advertisement
social1986

Untitled

Oct 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 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 _7.Andrey_and_Billiard
  8. {
  9. public class Program
  10. {
  11. public static void Main()
  12. {
  13. var numberOfEntities = int.Parse(Console.ReadLine());
  14. Dictionary<string, decimal> ProductsAndItsPrice = new Dictionary<string, decimal>();
  15.  
  16. for (int i = 0; i < numberOfEntities; i++)
  17. {
  18. var productAndItsPrice = Console.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  19. var product = productAndItsPrice[0];
  20. var price = decimal.Parse(productAndItsPrice[1]);
  21. //If the product thoes not exist, its added to dict with its price
  22. if (!ProductsAndItsPrice.ContainsKey(product))
  23. {
  24. ProductsAndItsPrice[product] = price;
  25. }
  26. //if the product exist it overwrite the price of the product
  27. else
  28. {
  29. ProductsAndItsPrice[product] = price;
  30. }
  31. }
  32.  
  33. var order = Console.ReadLine();
  34. var listOfClients = new List<Customer>();
  35.  
  36. while (order != "end of clients")
  37. {
  38. var result = order.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  39. var product = result[1];
  40. var quantity = int.Parse(result[2]);
  41. var name = result[0];
  42.  
  43.  
  44. // if the product that the client wants exist in the shop, creates new object(client)
  45. if (ProductsAndItsPrice.ContainsKey(product))
  46. {
  47. var client = new Customer();
  48. client.Name = name;
  49. client.Product = product;
  50. client.Quantity = quantity;
  51. client.Bill = client.Quantity * ProductsAndItsPrice[product];
  52. listOfClients.Add(client);
  53. }
  54. order = Console.ReadLine();
  55. }
  56.  
  57. var clientSBill = new Dictionary<string, Dictionary<Object, decimal>>();
  58.  
  59. foreach (var client in listOfClients)
  60. {
  61. if (!clientSBill.ContainsKey(client.Name))
  62. {
  63. clientSBill.Add(client.Name, new Dictionary<Object, decimal>());
  64. clientSBill[client.Name].Add(client, client.Bill);
  65. }
  66. else
  67. {
  68. if (!clientSBill[client.Name].ContainsKey(client.Product))
  69. {
  70. clientSBill[client.Name][client.Product] = client.Bill;
  71. clientSBill[client.Name][client.Quantity] = client.Quantity;
  72. }
  73. else
  74. {
  75. clientSBill[client.Name][client] += client.Bill;
  76. clientSBill[client.Name][client.Quantity] += client.Quantity;
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. public class Customer
  84. {
  85. public decimal Bill { get; set; }
  86. public string Name { get; set; }
  87. public string Product { get; set; }
  88. public int Quantity { get; set; }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement