static void Main(string[] args) { Dictionary <string, Person> personsDict = new Dictionary <string, Person>(); string command = string.Empty; while ((command = Console.ReadLine()) != "End") { string[] tokens = command.Split(' '); string name = tokens[0]; string personInfo = tokens[1]; if (!personsDict.ContainsKey(name)) { personsDict[name] = new Person(); } switch (personInfo) { case "company": string companyName = tokens[2]; string department = tokens[3]; double salary = double.Parse(tokens[4]); Company currentCompany = new Company { CompanyName = companyName, Department = department, Salary = salary }; personsDict[name].Company = currentCompany; break; case "pokemon": string pokemonNmae = tokens[2]; string pokemonType = tokens[3]; Pokemon currentPokemon = new Pokemon { PokemonName = pokemonNmae, PokemonType = pokemonType }; personsDict[name].Pokemons.Add(currentPokemon); break; case "parents": string parentName = tokens[2]; string parentBirthday = tokens[3]; Parent currentParent = new Parent { ParentName = parentName, ParentBirthday = parentBirthday }; personsDict[name].Parents.Add(currentParent); break; case "children": string childName = tokens[2]; string childBirthday = tokens[3]; Child currentChild = new Child { ChildName = childName, ChildBirthday = childBirthday }; personsDict[name].Childrens.Add(currentChild); break; case "car": string carModel = tokens[2]; double carSpeed = double.Parse(tokens[3]); Car currentCar = new Car { CarModel = carModel, CarSpeed = carSpeed }; personsDict[name].Car = currentCar; break; } } string searchByName = Console.ReadLine(); foreach (var pair in personsDict.Where(a => a.Key == searchByName)) { string name = pair.Key; Console.WriteLine(name); Console.WriteLine("Company:"); Console.Write(pair.Value.Company); Console.WriteLine("Car:"); Console.Write(pair.Value.Car); Console.WriteLine("Pokemon:"); pair.Value.Pokemons.ForEach(a => Console.Write(a.ToString())); Console.WriteLine("Parents:"); pair.Value.Parents.ForEach(a => Console.Write(a.ToString())); Console.WriteLine("Children:"); pair.Value.Childrens.ForEach(a => Console.Write(a.ToString())); } }
static void Main(string[] args) { Dictionary <string, Person> people = new Dictionary <string, Person>(); while (true) { string input = Console.ReadLine(); if (input == "End") { break; } string[] tokens = input.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string name = tokens[0]; string command = tokens[1]; if (!people.ContainsKey(name)) { people[name] = new Person(name); } if (command == "company") { string companyName = tokens[2]; string department = tokens[3]; double salary = double.Parse(tokens[4]); var company = new Company(companyName, department, salary); people[name].Company = company; } else if (command == "pokemon") { string namePok = tokens[2]; string typePok = tokens[3]; var pokeomon = new Pokemon(namePok, typePok); people[name].Pokemons.Add(pokeomon); } else if (command == "parents") { string parentName = tokens[2]; string parentBirth = tokens[3]; var parent = new Parent(parentName, parentBirth); people[name].Parents.Add(parent); } else if (command == "children") { string childName = tokens[2]; string childBirth = tokens[3]; var child = new Child(childName, childBirth); people[name].Children.Add(child); } else if (command == "car") { string carModel = tokens[2]; string carSpeed = tokens[3]; var car = new Car(carModel, carSpeed); people[name].Car = car; } } string searchName = Console.ReadLine(); Person person = people.Values.FirstOrDefault(p => p.Name == searchName); Console.WriteLine(person); }
static void Main(string[] args) { Dictionary <string, Person> people = new Dictionary <string, Person>(); while (true) { string[] input = Console.ReadLine().Split(); if (input[0] == "End") { break; } string name = input[0]; if (people.ContainsKey(name) == false) { people[name] = new Person(name); } switch (input[1]) { case "company": string companyName = input[2]; string department = input[3]; decimal salary = decimal.Parse(input[4]); Company company = new Company(companyName, department, salary); people[name].Company = company; break; case "pokemon": string pokemonName = input[2]; string type = input[3]; Pokemon pokemon = new Pokemon(pokemonName, type); people[name].Pokemons.Add(pokemon); break; case "parents": string parentName = input[2]; string parentBirthday = input[3]; Parent parent = new Parent(parentName, parentBirthday); people[name].Parents.Add(parent); break; case "children": string childName = input[2]; string childBirthday = input[3]; Child child = new Child(childName, childBirthday); people[name].Children.Add(child); break; case "car": string model = input[2]; int speed = int.Parse(input[3]); Car car = new Car(model, speed); people[name].Car = car; break; } } string searchedName = Console.ReadLine(); Person person = people.Values.FirstOrDefault(p => p.Name == searchedName); Console.WriteLine(person); }