Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- namespace _12.Google
- {
- public class StartUp
- {
- public static void Main()
- {
- var line = Console.ReadLine();
- var targetPeople = new Dictionary<string, Person>();
- while (line != "End")
- {
- var personTokens = line.Split(new []{' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
- var personName = personTokens[0];
- if (!targetPeople.ContainsKey(personName))
- {
- targetPeople[personName] = new Person(personName);
- }
- if (personTokens[1] == "company")
- {
- targetPeople[personName].SetCompany(
- personTokens[2],
- personTokens[3],
- decimal.Parse(personTokens[4]));
- }
- if (personTokens[1] == "car")
- {
- targetPeople[personName].SetCar(
- personTokens[2],
- double.Parse(personTokens[3]));
- }
- if (personTokens[1] == "pokemon")
- {
- targetPeople[personName].AddPokemon(new Pokemon(
- personTokens[2],
- personTokens[3]));
- }
- if (personTokens[1] == "parents")
- {
- targetPeople[personName].AddParent(new Relative(
- personTokens[2],
- DateTime.ParseExact(personTokens[3], "dd/MM/yyyy",CultureInfo.InvariantCulture)
- ));
- }
- if (personTokens[1] == "children")
- {
- targetPeople[personName].AddChildren(new Relative(
- personTokens[2],
- DateTime.ParseExact(personTokens[3],"dd/MM/yyyy",CultureInfo.InvariantCulture)
- ));
- }
- line = Console.ReadLine();
- }
- var outputPersonName = Console.ReadLine().Trim();
- if (targetPeople.ContainsKey(outputPersonName))
- {
- Console.WriteLine(targetPeople[outputPersonName].ToString());
- }
- }
- }
- class Person
- {
- private string name;
- private Company company;
- private Car car;
- private List<Pokemon> pokemons;
- private List<Relative> parents;
- private List<Relative> children;
- public string Name { get { return this.name; }}
- public Person(string name)
- {
- this.name = name;
- this.company = new Company();
- this.car = new Car();
- this.pokemons = new List<Pokemon>();
- this.parents = new List<Relative>();
- this.children = new List<Relative>();
- }
- public void SetCompany(string companyName, string departent, decimal salary)
- {
- this.company = new Company(companyName, departent, salary);
- }
- public void SetCar(string model, double speed)
- {
- this.car = new Car(model, speed);
- }
- public void AddPokemon(Pokemon pok)
- {
- this.pokemons.Add(pok);
- }
- public void AddParent(Relative parent)
- {
- this.parents.Add(parent);
- }
- public void AddChildren(Relative child)
- {
- this.children.Add(child);
- }
- public override string ToString()
- {
- var resultStr = this.name + "\r\n";
- resultStr += "Company:\r\n";
- if (this.company.Exists)
- {
- resultStr += this.company.ToString() + "\r\n";
- }
- resultStr += "Car:\r\n";
- if (this.car.Exists)
- {
- resultStr += this.car.ToString() + "\r\n";
- }
- resultStr += "Pokemon:\r\n";
- for (int i = 0; i < this.pokemons.Count; i++)
- {
- resultStr += this.pokemons[i].ToString() + "\r\n";
- }
- resultStr += "Parents:\r\n";
- for (int i = 0; i < this.parents.Count; i++)
- {
- resultStr += this.parents[i].ToString() + "\r\n";
- }
- resultStr += "Children:\r\n";
- for (int i = 0; i < this.children.Count; i++)
- {
- resultStr += this.children[i].ToString() + "\r\n";
- }
- return resultStr;
- }
- }
- class Company
- {
- private string companyName;
- private string departent;
- private decimal salary;
- private bool exists;
- public bool Exists
- {
- get { return this.exists; }
- }
- public Company(string companyName, string departent, decimal salary)
- {
- this.companyName = companyName;
- this.departent = departent;
- this.salary = salary;
- this.exists = true;
- }
- public Company()
- {
- }
- public override string ToString()
- {
- return $"{this.companyName} {this.departent} {this.salary:f2}";
- }
- }
- class Car
- {
- private string model;
- private double speed;
- private bool exists;
- public bool Exists { get { return this.exists; } }
- public Car(string model, double speed)
- {
- this.model = model;
- this.speed = speed;
- this.exists = true;
- }
- public Car()
- {
- }
- public override string ToString()
- {
- return $"{this.model} {this.speed}";
- }
- }
- class Pokemon
- {
- private string name;
- private string element;
- public string Name
- {
- get { return this.name; }
- }
- public string Element
- {
- get { return this.element; }
- }
- public Pokemon(string name, string element)
- {
- this.name = name;
- this.element = element;
- }
- public override string ToString()
- {
- return $"{this.Name} {this.Element}";
- }
- }
- class Relative
- {
- private string name;
- private DateTime birthDate;
- public Relative(string name, DateTime birthDate)
- {
- this.name = name;
- this.birthDate = birthDate;
- }
- public override string ToString()
- {
- return $"{this.name} {this.birthDate.ToString("dd/MM/yyyy",CultureInfo.InvariantCulture)}";
- }
- }
- }
Add Comment
Please, Sign In to add comment