AleksandarKostadinov

12. Google

Jul 4th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4.  
  5. namespace _12.Google
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             var line = Console.ReadLine();
  12.             var targetPeople = new Dictionary<string, Person>();
  13.  
  14.             while (line != "End")
  15.             {
  16.                 var personTokens = line.Split(new []{' ', '\t'}, StringSplitOptions.RemoveEmptyEntries);
  17.                 var personName = personTokens[0];
  18.                 if (!targetPeople.ContainsKey(personName))
  19.                 {
  20.                     targetPeople[personName] = new Person(personName);
  21.                 }
  22.  
  23.                 if (personTokens[1] == "company")
  24.                 {
  25.                     targetPeople[personName].SetCompany(
  26.                         personTokens[2],
  27.                         personTokens[3],
  28.                         decimal.Parse(personTokens[4]));
  29.                 }
  30.  
  31.                 if (personTokens[1] == "car")
  32.                 {
  33.                     targetPeople[personName].SetCar(
  34.                         personTokens[2],
  35.                         double.Parse(personTokens[3]));
  36.                 }
  37.  
  38.                 if (personTokens[1] == "pokemon")
  39.                 {
  40.                     targetPeople[personName].AddPokemon(new Pokemon(
  41.                         personTokens[2],
  42.                         personTokens[3]));
  43.                 }
  44.  
  45.                 if (personTokens[1] == "parents")
  46.                 {
  47.                     targetPeople[personName].AddParent(new Relative(
  48.                         personTokens[2],
  49.                         DateTime.ParseExact(personTokens[3], "dd/MM/yyyy",CultureInfo.InvariantCulture)
  50.                         ));
  51.                 }
  52.  
  53.                 if (personTokens[1] == "children")
  54.                 {
  55.                     targetPeople[personName].AddChildren(new Relative(
  56.                         personTokens[2],
  57.                         DateTime.ParseExact(personTokens[3],"dd/MM/yyyy",CultureInfo.InvariantCulture)
  58.                     ));
  59.                 }
  60.  
  61.                 line = Console.ReadLine();
  62.             }
  63.  
  64.             var outputPersonName = Console.ReadLine().Trim();
  65.  
  66.             if (targetPeople.ContainsKey(outputPersonName))
  67.             {
  68.                 Console.WriteLine(targetPeople[outputPersonName].ToString());
  69.             }
  70.         }
  71.     }
  72.  
  73.     class Person
  74.     {
  75.         private string name;
  76.         private Company company;
  77.         private Car car;
  78.         private List<Pokemon> pokemons;
  79.         private List<Relative> parents;
  80.         private List<Relative> children;
  81.  
  82.         public string Name { get { return this.name; }}
  83.         public Person(string name)
  84.         {
  85.             this.name = name;
  86.             this.company = new Company();
  87.             this.car = new Car();
  88.             this.pokemons = new List<Pokemon>();
  89.             this.parents = new List<Relative>();
  90.             this.children = new List<Relative>();
  91.         }
  92.  
  93.         public void SetCompany(string companyName, string departent, decimal salary)
  94.         {
  95.             this.company = new Company(companyName, departent, salary);
  96.         }
  97.  
  98.         public void SetCar(string model, double speed)
  99.         {
  100.             this.car = new Car(model, speed);
  101.         }
  102.  
  103.         public void AddPokemon(Pokemon pok)
  104.         {
  105.             this.pokemons.Add(pok);
  106.         }
  107.  
  108.         public void AddParent(Relative parent)
  109.         {
  110.             this.parents.Add(parent);
  111.         }
  112.  
  113.         public void AddChildren(Relative child)
  114.         {
  115.             this.children.Add(child);
  116.         }
  117.  
  118.         public override string ToString()
  119.         {
  120.             var resultStr = this.name + "\r\n";
  121.             resultStr += "Company:\r\n";
  122.             if (this.company.Exists)
  123.             {
  124.                 resultStr += this.company.ToString() + "\r\n";
  125.             }
  126.             resultStr += "Car:\r\n";
  127.             if (this.car.Exists)
  128.             {
  129.                 resultStr += this.car.ToString() + "\r\n";
  130.             }
  131.             resultStr += "Pokemon:\r\n";
  132.  
  133.             for (int i = 0; i < this.pokemons.Count; i++)
  134.             {
  135.                 resultStr += this.pokemons[i].ToString() + "\r\n";
  136.             }
  137.  
  138.             resultStr += "Parents:\r\n";
  139.             for (int i = 0; i < this.parents.Count; i++)
  140.             {
  141.                 resultStr += this.parents[i].ToString() + "\r\n";
  142.             }
  143.  
  144.             resultStr += "Children:\r\n";
  145.  
  146.             for (int i = 0; i < this.children.Count; i++)
  147.             {
  148.                 resultStr += this.children[i].ToString() + "\r\n";
  149.             }
  150.            
  151.             return resultStr;
  152.         }
  153.     }
  154.  
  155.     class Company
  156.     {
  157.         private string companyName;
  158.         private string departent;
  159.         private decimal salary;
  160.         private bool exists;
  161.  
  162.         public bool Exists
  163.         {
  164.             get { return this.exists; }
  165.         }
  166.  
  167.         public Company(string companyName, string departent, decimal salary)
  168.         {
  169.             this.companyName = companyName;
  170.             this.departent = departent;
  171.             this.salary = salary;
  172.             this.exists = true;
  173.         }
  174.  
  175.         public Company()
  176.         {
  177.            
  178.         }
  179.  
  180.         public override string ToString()
  181.         {
  182.             return $"{this.companyName} {this.departent} {this.salary:f2}";
  183.         }
  184.     }
  185.  
  186.     class Car
  187.     {
  188.         private string model;
  189.         private double speed;
  190.         private bool exists;
  191.  
  192.         public bool Exists { get { return this.exists; } }
  193.        
  194.         public Car(string model, double speed)
  195.         {
  196.             this.model = model;
  197.             this.speed = speed;
  198.             this.exists = true;
  199.         }
  200.  
  201.         public Car()
  202.         {
  203.            
  204.         }
  205.  
  206.         public override string ToString()
  207.         {
  208.             return $"{this.model} {this.speed}";
  209.         }
  210.     }
  211.  
  212.     class Pokemon
  213.     {
  214.         private string name;
  215.         private string element;
  216.  
  217.         public string Name
  218.         {
  219.             get { return this.name; }
  220.         }
  221.  
  222.  
  223.         public string Element
  224.         {
  225.             get { return this.element; }
  226.         }
  227.  
  228.         public Pokemon(string name, string element)
  229.         {
  230.             this.name = name;
  231.             this.element = element;
  232.         }
  233.  
  234.        
  235.  
  236.         public override string ToString()
  237.         {
  238.             return $"{this.Name} {this.Element}";
  239.         }
  240.     }
  241.  
  242.     class Relative
  243.     {
  244.         private string name;
  245.         private DateTime birthDate;
  246.  
  247.        
  248.         public Relative(string name, DateTime birthDate)
  249.         {
  250.             this.name = name;
  251.             this.birthDate = birthDate;
  252.         }
  253.  
  254.         public override string ToString()
  255.         {
  256.             return $"{this.name} {this.birthDate.ToString("dd/MM/yyyy",CultureInfo.InvariantCulture)}";
  257.         }
  258.     }
  259. }
Add Comment
Please, Sign In to add comment