Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 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. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int num = int.Parse(Console.ReadLine());
  14.  
  15. var entities = new Dictionary<string, decimal>();
  16.  
  17. for (int i = 0; i < num; i++)
  18. {
  19. string[] cmds = Console.ReadLine().Split('-').ToArray();
  20.  
  21. string product = cmds[0];
  22. decimal price = decimal.Parse(cmds[1]);
  23.  
  24. if (!entities.ContainsKey(product))
  25. {
  26. entities.Add(product, 0);
  27. }
  28. entities[product] = price;
  29.  
  30.  
  31. }
  32. string commands = Console.ReadLine();
  33.  
  34. List<Customer> customer = new List<Customer>();
  35.  
  36. while (commands != "end of clients")
  37. {
  38. Customer custom = new Customer();
  39.  
  40. var dict = new Dictionary<string, int>();
  41.  
  42. string[] input = commands.Split(new char[] { '-', ',' }, StringSplitOptions.RemoveEmptyEntries);
  43.  
  44. string name = input[0];
  45.  
  46. string product = input[1];
  47.  
  48. int quantity = int.Parse(input[2]);
  49.  
  50. if (!entities.ContainsKey(product))
  51. {
  52.  
  53.  
  54. }
  55. else
  56. {
  57. bool getIn = true;
  58. foreach (var student in customer.Where(x=> x.Name==name))
  59. {
  60.  
  61. if (!student.ShopList.ContainsKey(product))
  62. {
  63. student.ShopList.Add(product, 0);
  64.  
  65. }
  66. student.ShopList[product] += quantity;
  67.  
  68. getIn = false;
  69. }
  70. if (getIn)
  71. {
  72. custom.Name = name;
  73. dict.Add(product, quantity);
  74. custom.ShopList = dict;
  75. customer.Add(custom);
  76. }
  77.  
  78. }
  79.  
  80.  
  81.  
  82. commands = Console.ReadLine();
  83.  
  84. }
  85.  
  86. decimal totalBill = 0m;
  87. foreach (var student in customer.OrderBy(x => x.Name))
  88. {
  89. Console.WriteLine(student.Name);
  90.  
  91. foreach (var kvp in student.ShopList)
  92. {
  93. Console.WriteLine($"-- {kvp.Key} - {kvp.Value}");
  94.  
  95. foreach (var entity in entities)
  96. {
  97. if (kvp.Key == entity.Key)
  98. {
  99. decimal bill = bill = kvp.Value * entity.Value;
  100.  
  101. Console.WriteLine($"Bill: {bill:F2}");
  102. totalBill += bill;
  103.  
  104. }
  105. }
  106. }
  107. }
  108. Console.WriteLine($"Total bill: {totalBill:F2}");
  109.  
  110.  
  111. }
  112.  
  113. }
  114.  
  115. class Customer
  116. {
  117. public string Name { get; set; }
  118.  
  119. public Dictionary<string, int> ShopList { get; set; }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement