vstoyanov

Google

Feb 17th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.49 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6.  
  7. class Program
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         string[] inputData = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  12.  
  13.         Dictionary<string, Person> dictionary = new Dictionary<string, Person>();
  14.  
  15.        
  16.         while (inputData[0]!="End")
  17.         {
  18.             if(inputData[1]== "company")
  19.             {
  20.                 string name = inputData[0];
  21.                 string companyName = inputData[2];
  22.                 string departmentName = inputData[3];
  23.                 double salary = double.Parse(inputData[4]);
  24.                 if (!dictionary.ContainsKey(name))
  25.                 {
  26.                     dictionary.Add(name, new Person());
  27.                     Company company = new Company(companyName,departmentName,salary);
  28.                     dictionary[name].Company=company;
  29.  
  30.                        
  31.                    
  32.                 }
  33.                 else
  34.                 {
  35.                     Company company = new Company(companyName, departmentName, salary);
  36.                     dictionary[name].Company = company;
  37.                 }
  38.  
  39.             }else if (inputData[1] == "car")
  40.             {
  41.                 string name = inputData[0];
  42.                 string carModel = inputData[2];
  43.                 string carSpeed = inputData[3];
  44.                 if (!dictionary.ContainsKey(name))
  45.                 {
  46.                     dictionary.Add(name, new Person());
  47.                     Car car = new Car(carModel, carSpeed);
  48.                     dictionary[name].Car = car;
  49.                    
  50.                 }
  51.                 else
  52.                 {
  53.                     Car car = new Car(carModel, carSpeed);
  54.                     dictionary[name].Car = car;
  55.                 }
  56.  
  57.             }else if (inputData[1] == "pokemon")
  58.             {
  59.                 string name = inputData[0];
  60.                 string pokemonName = inputData[2];
  61.                 string pokemonType = inputData[3];
  62.  
  63.                 if (!dictionary.ContainsKey(name))
  64.                 {
  65.                     dictionary.Add(name, new Person());
  66.  
  67.                     Pokemon onePokemon = new Pokemon(pokemonName, pokemonType);
  68.                     List<Pokemon> pokemons = new List<Pokemon>();
  69.  
  70.                     pokemons.Add(onePokemon);
  71.  
  72.                     dictionary[name].Pokemons = pokemons;
  73.  
  74.                 }
  75.                 else
  76.                 {
  77.                    
  78.                     Pokemon onePokemon = new Pokemon(pokemonName, pokemonType);
  79.  
  80.                     if (dictionary[name].Pokemons == null)
  81.                     {
  82.                         List<Pokemon> pokemons = new List<Pokemon>();
  83.  
  84.                         pokemons.Add(onePokemon);
  85.  
  86.                         dictionary[name].Pokemons = pokemons;
  87.                     }
  88.                     else
  89.                     {
  90.  
  91.  
  92.                         dictionary[name].Pokemons.Add(onePokemon);
  93.                     }
  94.                 }
  95.             }else if (inputData[1] == "parents")
  96.             {
  97.                 string name = inputData[0];
  98.                 string parentName = inputData[2];
  99.                 string parentBirtDay = inputData[3];
  100.                 if (!dictionary.ContainsKey(name))
  101.                 {
  102.                     dictionary.Add(name, new Person());
  103.                     List<Parrent> parrents = new List<Parrent>();
  104.  
  105.                     Parrent parrent = new Parrent(parentName, parentBirtDay);
  106.                     parrents.Add(parrent);
  107.                     dictionary[name].Parrents = parrents;
  108.                 }
  109.                 else
  110.                 {
  111.                     Parrent parrent = new Parrent(parentName, parentBirtDay);
  112.  
  113.                     if (dictionary[name].Parrents == null)
  114.                     {
  115.                         List<Parrent> parrents = new List<Parrent>();
  116.  
  117.  
  118.                         parrents.Add(parrent);
  119.                         dictionary[name].Parrents = parrents;
  120.                     }
  121.                     else
  122.                     {
  123.  
  124.                         dictionary[name].Parrents.Add(parrent);
  125.                     }
  126.                 }
  127.             }else if(inputData[1]== "children")
  128.             {
  129.                 string name = inputData[0];
  130.                 string childName = inputData[2];
  131.                 string childBirtDay = inputData[3];
  132.                 if (!dictionary.ContainsKey(name))
  133.                 {
  134.                     dictionary.Add(name, new Person());
  135.                     Children children = new Children(childName, childBirtDay);
  136.  
  137.                     List<Children> list=new List<Children>();
  138.  
  139.                     list.Add(children);
  140.                     dictionary[name].Childrens = list;
  141.                 }
  142.                 else
  143.                 {
  144.                     Children children = new Children(childName, childBirtDay);
  145.                     if (dictionary[name].Childrens == null)
  146.                     {
  147.                         List<Children> list = new List<Children>();
  148.  
  149.                         list.Add(children);
  150.                         dictionary[name].Childrens = list;
  151.  
  152.                     }
  153.                     else
  154.                     {
  155.  
  156.                         dictionary[name].Childrens.Add(children);
  157.                     }
  158.                 }
  159.             }
  160.  
  161.  
  162.             inputData = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  163.         }
  164.  
  165.         string person = Console.ReadLine();
  166.  
  167.         foreach (var item in dictionary)
  168.         {
  169.             if (item.Key == person)
  170.             {
  171.                 Console.WriteLine(item.Key);
  172.                 Console.WriteLine("Company:");
  173.  
  174.                 if (item.Value.Company != null)
  175.                 {
  176.                     Console.WriteLine($"{item.Value.Company.CompanyName} {item.Value.Company.Department} {item.Value.Company.Salary:F2}");
  177.                 }
  178.                 Console.WriteLine("Car:");
  179.                 if (item.Value.Car != null)
  180.                 {
  181.                     Console.WriteLine($"{item.Value.Car.CarModel} {item.Value.Car.CarSpeed}");
  182.                 }
  183.                 Console.WriteLine("Pokemon:");
  184.                 if (item.Value.Pokemons != null)
  185.                 {
  186.                     var collection = item.Value.Pokemons.ToList();
  187.                     for (int i = 0; i < collection.Count; i++)
  188.                     {
  189.                         Console.WriteLine(collection[i].PokemonName+" "+collection[i].PokemonType);
  190.                     }
  191.  
  192.                  
  193.  
  194.                    
  195.                 }
  196.                 Console.WriteLine("Parents:");
  197.                 if (item.Value.Parrents != null)
  198.                 {
  199.                     var collection = item.Value.Parrents.ToList();
  200.  
  201.                     for (int i = 0; i < item.Value.Parrents.Count; i++)
  202.                     {
  203.                         Console.WriteLine(collection[i].ParrentName +" "+collection[i].ParrentBirtDay);
  204.                     }
  205.  
  206.                 }
  207.                 Console.WriteLine("Children:");
  208.  
  209.                 if (item.Value.Childrens != null)
  210.                 {
  211.                     var collection = item.Value.Childrens.ToList();
  212.                     for (int i = 0; i < collection.Count; i++)
  213.                     {
  214.                         Console.WriteLine(collection[i].ChildName+" "+collection[i].ChildBirtDay);
  215.                     }
  216.                 }
  217.  
  218.                 break;
  219.             }
  220.         }
  221.  
  222.     }
  223. }
Add Comment
Please, Sign In to add comment