Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 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 AndreyAndBilliard
  8. {
  9.  
  10.  
  11. public class Customer
  12. {
  13. public String Name { get; set; }
  14. public Dictionary<string, decimal> Shoplist { get; set; }
  15. public decimal Bill { get; set; }
  16.  
  17. }
  18.  
  19.  
  20. public class AndreyAndBilliard
  21. {
  22. public static void Main()
  23. {
  24. var line = Console.ReadLine();
  25. var sales = new Dictionary<string, decimal>();
  26. var buyers = new List<Customer>();
  27. var end = int.Parse(line);
  28. for (int i = 0; i < end; i++)
  29. {
  30. line = Console.ReadLine();
  31. var input = line.Split('-');
  32. if (!sales.ContainsKey(input[0]))
  33. {
  34. sales.Add(input[0], decimal.Parse(input[1]));
  35. }
  36. sales[input[0]] = decimal.Parse(input[1]);
  37.  
  38. }
  39. while (line != "end of clients")
  40. {
  41. line = Console.ReadLine();
  42. if (line != "end of clients")
  43. {
  44. var input = line.Split("-,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  45. var customerName = input[0];
  46. var desiredProduct = input[1];
  47. var quantityProduct = input[2];
  48. if (sales.ContainsKey(desiredProduct))
  49. {
  50. var customer = new Customer();
  51. customer.Name = customerName;
  52. customer.Shoplist = new Dictionary<string, decimal>();
  53. customer.Bill = new decimal();
  54. customer.Bill = (decimal)(decimal.Parse(quantityProduct)* sales[desiredProduct]);
  55. customer.Shoplist.Add(desiredProduct, int.Parse(quantityProduct));
  56. buyers.Add(customer);
  57. }
  58. }
  59.  
  60. }
  61.  
  62. var sorted = buyers.OrderBy(x => x.Name);
  63. foreach (var buyer in sorted)
  64. {
  65. Console.WriteLine(buyer.Name);
  66. foreach (var item in buyer.Shoplist)
  67. {
  68. Console.WriteLine($"-- {item.Key} - {item.Value}");
  69. }
  70. Console.WriteLine($"Bill: {buyer.Bill:f2}");
  71. }
  72. var total = 0m;
  73. foreach (var item in buyers)
  74. {
  75. total += item.Bill;
  76. }
  77. Console.WriteLine($"Total bill: {total:f2}");
  78.  
  79.  
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement