Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string[] people = Console.ReadLine().Split(new char[] { '=', ';' }, StringSplitOptions.RemoveEmptyEntries);
  10. string[] products = Console.ReadLine().Split(new char[] { '=', ';' }, StringSplitOptions.RemoveEmptyEntries);
  11. List<Person> persons = new List<Person>();
  12. List<Product> prods = new List<Product>();
  13.  
  14. try
  15. {
  16. for (int i = 0; i < products.Length; i += 2)
  17. {
  18. Product product = new Product(products[i], decimal.Parse(products[i + 1]));
  19. prods.Add(product);
  20. }
  21. }
  22. catch (ArgumentException argEx)
  23. {
  24. Console.WriteLine(argEx.Message);
  25. return;
  26. }
  27.  
  28. try
  29. {
  30.  
  31. for (int i = 0; i < people.Length; i += 2)
  32. {
  33. Person person = new Person(people[i], decimal.Parse(people[i + 1]));
  34. persons.Add(person);
  35. }
  36. }
  37. catch (ArgumentException argEx)
  38. {
  39. Console.WriteLine(argEx.Message);
  40. return;
  41. }
  42.  
  43.  
  44. string input = Console.ReadLine();
  45. while (input != "END")
  46. {
  47. string[] arg = input.Split();
  48. Person personX = persons.FirstOrDefault(p => p.Name == arg[0]);
  49. Product productX = prods.FirstOrDefault(p => p.Name == arg[1]);
  50. personX.AddProduct(personX, productX);
  51. input = Console.ReadLine();
  52. }
  53.  
  54. string c = "";
  55. foreach (var p in persons)
  56. {
  57. c = ($"{p.Name} - ");
  58. if (p.Bag.Count > 0)
  59. {
  60. foreach (var pr in p.Bag)
  61. {
  62. c += ($"{pr.Name}, ");
  63. }
  64. }
  65. else
  66. {
  67. c += "Nothing bought";
  68. }
  69. Console.WriteLine(c.TrimEnd(new char[] { ',', ' ' }));
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement