vasildiavolo

Untitled

Jun 12th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. Dictionary<string, decimal> products = GetProducts(n);
  12. SortedDictionary<string, Dictionary<string, int>> customers = new SortedDictionary<string, Dictionary<string, int>>();
  13. string[] input = Console.ReadLine().Split('-', ',').ToArray();
  14. while (input[0] != "end of clients")
  15. {
  16. Dictionary<string, int> temp = new Dictionary<string, int>();
  17. temp.Add(input[1], int.Parse(input[2]));
  18. string customer = input[0];
  19. string product = input[1];
  20. int quantity = int.Parse(input[2]);
  21.  
  22. if (customers.ContainsKey(customer) && products.ContainsKey(product))
  23. {
  24. if (customers[customer].ContainsKey(product))
  25. {
  26. customers[customer][product] += quantity;
  27. }
  28. else
  29. {
  30. customers[customer].Add(product, quantity);
  31. }
  32. }
  33. else if (products.ContainsKey(product))
  34. {
  35. customers.Add(input[0], temp);
  36. }
  37.  
  38. input = Console.ReadLine().Split('-', ',').ToArray();
  39. }
  40.  
  41. decimal totalBill = 0;
  42. foreach (var customer in customers)
  43. {
  44. decimal bill = 0;
  45.  
  46. Console.WriteLine(customer.Key);
  47. foreach (var pair in customers[customer.Key])
  48. {
  49. Console.WriteLine($"-- {pair.Key} - {pair.Value}");
  50. bill += pair.Value * products[pair.Key];
  51. }
  52. Console.WriteLine($"Bill: {bill:f2}");
  53. totalBill += bill;
  54. }
  55. Console.WriteLine($"Total bill: {totalBill:f2}");
  56. }
  57.  
  58.  
  59. static Dictionary<string, decimal> GetProducts(int n)
  60. {
  61. Dictionary<string, decimal> products = new Dictionary<string, decimal>();
  62. for (int i = 0; i < n; i++)
  63. {
  64. string[] input = Console.ReadLine().Split('-').ToArray();
  65. if (products.ContainsKey(input[0]))
  66. {
  67. products[input[0]] = decimal.Parse(input[1]);
  68. }
  69. else
  70. {
  71. products.Add(input[0], decimal.Parse(input[1]));
  72. }
  73. }
  74. return products;
  75. }
  76. }
  77.  
  78. class Customer
  79. {
  80. public string Name { get; set; }
  81. public Dictionary<string, int> Bought { get; set; }
  82. public decimal Bill { get; set; }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment