Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 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 Book_library
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<Customer> customers = new List<Customer>();
  14. Dictionary<string, decimal> shop = new Dictionary<string, decimal>();
  15. int n = int.Parse(Console.ReadLine());
  16. for (int i = 0; i < n; i++)
  17. {
  18. string[] tokens = Console.ReadLine().Split('-').ToArray();
  19. if (!shop.ContainsKey(tokens[0]))
  20. {
  21. shop.Add(tokens[0], decimal.Parse(tokens[1]));
  22. }
  23. else
  24. {
  25. shop[tokens[0]] = decimal.Parse(tokens[1]);
  26. }
  27. }
  28.  
  29. while (true)
  30. {
  31. string input = Console.ReadLine();
  32. if (input== "end of clients")
  33. {
  34. break;
  35. }
  36. string[] tokens = input.Split(new char[]{'-', ','}, StringSplitOptions.RemoveEmptyEntries);
  37. if (shop.ContainsKey(tokens[1]))
  38. {
  39. var primerno = new KeyValuePair<string, int>(tokens[1], int.Parse(tokens[2]));
  40. Customer customer = new Customer() { Name = tokens[0], ShopList = primerno };
  41. foreach (var item in shop)
  42. {
  43. if (item.Key.Equals(tokens[1]))
  44. {
  45. customer.Bill = item.Value * decimal.Parse(tokens[2]);
  46. }
  47. }
  48. customers.Add(customer);
  49. }
  50.  
  51. }
  52. decimal totalBill = 0;
  53. foreach (var customer in customers)
  54. {
  55. totalBill += customer.Bill;
  56. Console.WriteLine(customer.Name);
  57. Console.WriteLine($"-- {customer.ShopList.Key} - {customer.ShopList.Value}");
  58. Console.WriteLine($"Bill: {customer.Bill:f2}");
  59. Console.WriteLine($"Totall bill: {totalBill:f2}");
  60. }
  61. }
  62. }
  63. public class Customer
  64. {
  65. public KeyValuePair<string, int> ShopList { get; set; }
  66. public decimal Bill { get; set; }
  67. public string Name { get; set; }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement