Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- string[] people = Console.ReadLine().Split(new char[] { '=', ';' }, StringSplitOptions.RemoveEmptyEntries);
- string[] products = Console.ReadLine().Split(new char[] { '=', ';' }, StringSplitOptions.RemoveEmptyEntries);
- List<Person> persons = new List<Person>();
- List<Product> prods = new List<Product>();
- try
- {
- for (int i = 0; i < products.Length; i += 2)
- {
- Product product = new Product(products[i], decimal.Parse(products[i + 1]));
- prods.Add(product);
- }
- }
- catch (ArgumentException argEx)
- {
- Console.WriteLine(argEx.Message);
- return;
- }
- try
- {
- for (int i = 0; i < people.Length; i += 2)
- {
- Person person = new Person(people[i], decimal.Parse(people[i + 1]));
- persons.Add(person);
- }
- }
- catch (ArgumentException argEx)
- {
- Console.WriteLine(argEx.Message);
- return;
- }
- string input = Console.ReadLine();
- while (input != "END")
- {
- string[] arg = input.Split();
- Person personX = persons.FirstOrDefault(p => p.Name == arg[0]);
- Product productX = prods.FirstOrDefault(p => p.Name == arg[1]);
- personX.AddProduct(personX, productX);
- input = Console.ReadLine();
- }
- string c = "";
- foreach (var p in persons)
- {
- c = ($"{p.Name} - ");
- if (p.Bag.Count > 0)
- {
- foreach (var pr in p.Bag)
- {
- c += ($"{pr.Name}, ");
- }
- }
- else
- {
- c += "Nothing bought";
- }
- Console.WriteLine(c.TrimEnd(new char[] { ',', ' ' }));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement