Example #1
0
        static void Main(string[] args)
        {
            List <string> models   = new List <string>();
            List <string> robotIds = new List <string>();

            List <string> names      = new List <string>();
            List <string> citizenIds = new List <string>();
            List <int>    ages       = new List <int>();

            string[] comand = Console.ReadLine().Split();

            while (comand[0] != "End")
            {
                if (comand.Length == 2)
                {
                    models.Add(comand[0]);
                    robotIds.Add(comand[1]);
                }
                else
                {
                    names.Add(comand[0]);
                    ages.Add(int.Parse(comand[1]));
                    citizenIds.Add(comand[2]);
                }

                comand = Console.ReadLine().Split();
            }

            string fakeIdSnippet = Console.ReadLine();

            Citizens citizens = new Citizens(citizenIds, names, ages);

            Robots robots = new Robots(robotIds, models);

            Console.WriteLine(string.Join(" ", citizens.IdentifyCriminals(fakeIdSnippet)));
            Console.WriteLine(string.Join(" ", robots.IdentifyCriminals(fakeIdSnippet)));
        }
Example #2
0
        public void Run()
        {
            string[] inputArgs = Console.ReadLine().Split();

            while (inputArgs[0] != "End")
            {
                if (inputArgs.Length == 3)
                {
                    string name = inputArgs[0];
                    int    age  = int.Parse(inputArgs[1]);
                    string id   = inputArgs[2];

                    Citizens citizens = new Citizens(id, name, age);

                    identifications.Add(citizens);
                }
                else if (inputArgs.Length == 2)
                {
                    string model = inputArgs[0];
                    string id    = inputArgs[1];

                    Robots robots = new Robots(id, model);

                    identifications.Add(robots);
                }

                inputArgs = Console.ReadLine().Split();
            }

            string digitsFakeId = Console.ReadLine();

            foreach (var id in identifications.Where(x => x.Id.EndsWith(digitsFakeId)))
            {
                Console.WriteLine(id.Id);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            List <IBuyer> inhabitants = new List <IBuyer>();

            int n = int.Parse(Console.ReadLine());

            IBuyer inhabitant = null;

            for (int i = 0; i < n; i++)
            {
                string[] curInhabitant = Console.ReadLine().Split();
                if (curInhabitant.Length == 4)
                {
                    inhabitant = new Citizens(curInhabitant[0],
                                              int.Parse(curInhabitant[1]),
                                              curInhabitant[2],
                                              curInhabitant[3]);
                }
                else
                {
                    inhabitant = new Rebel(curInhabitant[0],
                                           int.Parse(curInhabitant[1]),
                                           curInhabitant[2]);
                }
                inhabitants.Add(inhabitant);
            }
            int    totalFood = 0;
            string command;

            while ((command = Console.ReadLine()) != "End")
            {
                inhabitant = inhabitants.FirstOrDefault(el => el.Name == command);
                if (inhabitant != null)
                {
                    IBuyer curPerson = (IBuyer)inhabitant;
                    curPerson.BuyFood();
                }
            }

            foreach (var item in inhabitants)
            {
                totalFood += item.Food;
            }
            Console.WriteLine(totalFood);

            //Task on 5.	Birthday Celebrations
            //string command;
            //while ((command = Console.ReadLine()) != "End")
            //{

            //    string[] curInhabitant = command.Split();
            //    IInhabitable inhabitant = null;
            //    if (curInhabitant[0] == "Citizen")
            //    {
            //        inhabitant = new Citizens(curInhabitant[1],
            //            int.Parse(curInhabitant[2]),
            //            curInhabitant[3],
            //            curInhabitant[4]);

            //    }
            //    else if (curInhabitant[0] == "Robot")
            //    {
            //        inhabitant = new Robot(curInhabitant[1],
            //            (curInhabitant[2]));

            //    }
            //    else if(curInhabitant[0] == "Pet")
            //    {
            //        inhabitant = new Pet(curInhabitant[1],
            //            (curInhabitant[2]));

            //    }

            //    inhabitants.Add(inhabitant);

            //}

            //string criteria = Console.ReadLine();

            //inhabitants.Where(el => el.Birthday != null)
            //    .ToList()
            //    .Where(el => el.Birthday.EndsWith(criteria))
            //    .ToList()
            //    .ForEach(el => Console.WriteLine(el.Birthday));
        }