static void Main(string[] args)
    {
        Solve  people = new Solve();
        string input  = Console.ReadLine();

        while (input != "End")
        {
            string[] tokens = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens[1] == "company")
            {
                people.AddCompany(tokens[0], new Company(tokens[2], tokens[3], decimal.Parse(tokens[4])));
            }
            else if (tokens[1] == "car")
            {
                people.AddCar(tokens[0], new Car(tokens[2], int.Parse(tokens[3])));
            }
            else if (tokens[1] == "pokemon")
            {
                people.AddPokemon(tokens[0], new Pokemon(tokens[2], tokens[3]));
            }
            else if (tokens[1] == "parents")
            {
                people.AddParent(tokens[0], new Parents(tokens[2], tokens[3]));
            }
            else if (tokens[1] == "children")
            {
                people.AddChild(tokens[0], new Children(tokens[2], tokens[3]));
            }
            input = Console.ReadLine();
        }
        string name = Console.ReadLine();

        people.Print(name);
    }
Beispiel #2
0
    static void Main(string[] args)
    {
        Solve elements = new Solve();
        int   n        = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            string[] tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length == 4)
            {
                elements.AddEngine(new Engine(tokens[0], int.Parse(tokens[1]), int.Parse(tokens[2]), tokens[3]));
            }
            else
            {
                if (tokens.Length == 2)
                {
                    elements.AddEngine(new Engine(tokens[0], int.Parse(tokens[1]), null, null));
                }
                else if (tokens.Length == 3)
                {
                    if (Regex.IsMatch(tokens[2], @"[0-9]+"))
                    {
                        elements.AddEngine(new Engine(tokens[0], int.Parse(tokens[1]), int.Parse(tokens[2]), null));
                    }
                    else
                    {
                        elements.AddEngine(new Engine(tokens[0], int.Parse(tokens[1]), null, tokens[2]));
                    }
                }
            }
        }
        int m = int.Parse(Console.ReadLine());

        for (int i = 0; i < m; i++)
        {
            string[] tokens = Console.ReadLine().Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length == 4)
            {
                elements.AddCar(new Car(tokens[0], tokens[1], int.Parse(tokens[2]), tokens[3]));
            }
            else
            {
                if (tokens.Length == 2)
                {
                    elements.AddCar(new Car(tokens[0], tokens[1], null, null));
                }
                else if (tokens.Length == 3)
                {
                    if (Regex.IsMatch(tokens[2], @"[0-9]+"))
                    {
                        elements.AddCar(new Car(tokens[0], tokens[1], int.Parse(tokens[2]), null));
                    }
                    else
                    {
                        elements.AddCar(new Car(tokens[0], tokens[1], null, tokens[2]));
                    }
                }
            }
        }
        elements.PrintResults();
    }