Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class StartUp
- {
- public static void Main()
- {
- var persons = new Dictionary<string, Person>();
- var personsInput = Console.ReadLine()
- .Split(new[] { '=', ';' },StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < personsInput.Length; i+=2)
- {
- try
- {
- var name = personsInput[i];
- var money = decimal.Parse(personsInput[i + 1]);
- var person = new Person(name, money);
- if (!persons.ContainsKey(name))
- {
- persons[name] = person;
- }
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- Environment.Exit(0);
- }
- }
- var productsInput = Console.ReadLine()
- .Split(new[] { ';', '=' }, StringSplitOptions.RemoveEmptyEntries);
- var products = new Dictionary<string, Product>();
- for (int i = 0; i < productsInput.Length; i+=2)
- {
- try
- {
- var productName = productsInput[i];
- var cost = decimal.Parse(productsInput[i + 1]);
- var product = new Product(productName, cost);
- if (!products.ContainsKey(productName))
- {
- products[productName] = product;
- }
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- Environment.Exit(0);
- }
- }
- string input;
- while ((input = Console.ReadLine()) != "END")
- {
- try
- {
- var currentPersonToBuy = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var personsName = currentPersonToBuy[0];
- var productToBuy = currentPersonToBuy[1];
- persons[personsName].AddProduct(products[productToBuy]);
- Console.WriteLine($"{personsName} bought {productToBuy}");
- }
- catch (ArgumentException ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- foreach (var person in persons.Values)
- {
- if (person.Products.Count > 0)
- {
- Console.WriteLine(person);
- }
- else
- {
- Console.WriteLine($"{person.Name} - Nothing bought");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement