Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- class Program
- {
- static void Main(string[] args)
- {
- string[] inputData = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- Dictionary<string, Person> dictionary = new Dictionary<string, Person>();
- while (inputData[0]!="End")
- {
- if(inputData[1]== "company")
- {
- string name = inputData[0];
- string companyName = inputData[2];
- string departmentName = inputData[3];
- double salary = double.Parse(inputData[4]);
- if (!dictionary.ContainsKey(name))
- {
- dictionary.Add(name, new Person());
- Company company = new Company(companyName,departmentName,salary);
- dictionary[name].Company=company;
- }
- else
- {
- Company company = new Company(companyName, departmentName, salary);
- dictionary[name].Company = company;
- }
- }else if (inputData[1] == "car")
- {
- string name = inputData[0];
- string carModel = inputData[2];
- string carSpeed = inputData[3];
- if (!dictionary.ContainsKey(name))
- {
- dictionary.Add(name, new Person());
- Car car = new Car(carModel, carSpeed);
- dictionary[name].Car = car;
- }
- else
- {
- Car car = new Car(carModel, carSpeed);
- dictionary[name].Car = car;
- }
- }else if (inputData[1] == "pokemon")
- {
- string name = inputData[0];
- string pokemonName = inputData[2];
- string pokemonType = inputData[3];
- if (!dictionary.ContainsKey(name))
- {
- dictionary.Add(name, new Person());
- Pokemon onePokemon = new Pokemon(pokemonName, pokemonType);
- List<Pokemon> pokemons = new List<Pokemon>();
- pokemons.Add(onePokemon);
- dictionary[name].Pokemons = pokemons;
- }
- else
- {
- Pokemon onePokemon = new Pokemon(pokemonName, pokemonType);
- if (dictionary[name].Pokemons == null)
- {
- List<Pokemon> pokemons = new List<Pokemon>();
- pokemons.Add(onePokemon);
- dictionary[name].Pokemons = pokemons;
- }
- else
- {
- dictionary[name].Pokemons.Add(onePokemon);
- }
- }
- }else if (inputData[1] == "parents")
- {
- string name = inputData[0];
- string parentName = inputData[2];
- string parentBirtDay = inputData[3];
- if (!dictionary.ContainsKey(name))
- {
- dictionary.Add(name, new Person());
- List<Parrent> parrents = new List<Parrent>();
- Parrent parrent = new Parrent(parentName, parentBirtDay);
- parrents.Add(parrent);
- dictionary[name].Parrents = parrents;
- }
- else
- {
- Parrent parrent = new Parrent(parentName, parentBirtDay);
- if (dictionary[name].Parrents == null)
- {
- List<Parrent> parrents = new List<Parrent>();
- parrents.Add(parrent);
- dictionary[name].Parrents = parrents;
- }
- else
- {
- dictionary[name].Parrents.Add(parrent);
- }
- }
- }else if(inputData[1]== "children")
- {
- string name = inputData[0];
- string childName = inputData[2];
- string childBirtDay = inputData[3];
- if (!dictionary.ContainsKey(name))
- {
- dictionary.Add(name, new Person());
- Children children = new Children(childName, childBirtDay);
- List<Children> list=new List<Children>();
- list.Add(children);
- dictionary[name].Childrens = list;
- }
- else
- {
- Children children = new Children(childName, childBirtDay);
- if (dictionary[name].Childrens == null)
- {
- List<Children> list = new List<Children>();
- list.Add(children);
- dictionary[name].Childrens = list;
- }
- else
- {
- dictionary[name].Childrens.Add(children);
- }
- }
- }
- inputData = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- }
- string person = Console.ReadLine();
- foreach (var item in dictionary)
- {
- if (item.Key == person)
- {
- Console.WriteLine(item.Key);
- Console.WriteLine("Company:");
- if (item.Value.Company != null)
- {
- Console.WriteLine($"{item.Value.Company.CompanyName} {item.Value.Company.Department} {item.Value.Company.Salary:F2}");
- }
- Console.WriteLine("Car:");
- if (item.Value.Car != null)
- {
- Console.WriteLine($"{item.Value.Car.CarModel} {item.Value.Car.CarSpeed}");
- }
- Console.WriteLine("Pokemon:");
- if (item.Value.Pokemons != null)
- {
- var collection = item.Value.Pokemons.ToList();
- for (int i = 0; i < collection.Count; i++)
- {
- Console.WriteLine(collection[i].PokemonName+" "+collection[i].PokemonType);
- }
- }
- Console.WriteLine("Parents:");
- if (item.Value.Parrents != null)
- {
- var collection = item.Value.Parrents.ToList();
- for (int i = 0; i < item.Value.Parrents.Count; i++)
- {
- Console.WriteLine(collection[i].ParrentName +" "+collection[i].ParrentBirtDay);
- }
- }
- Console.WriteLine("Children:");
- if (item.Value.Childrens != null)
- {
- var collection = item.Value.Childrens.ToList();
- for (int i = 0; i < collection.Count; i++)
- {
- Console.WriteLine(collection[i].ChildName+" "+collection[i].ChildBirtDay);
- }
- }
- break;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment