Example #1
0
        public void Run()
        {
            string input = reader.ReadLine();

            while (input != "End")
            {
                string[] splitted = input.Split();

                ICitizen citizen = null;
                IRobot   robot   = null;
                if (splitted.Length == 3)
                {
                    citizen = citizenFactory.GetCitizen(splitted);
                    list.Add(citizen.Id);
                }
                else
                {
                    robot = robotFactory.GetRobot(splitted);
                    list.Add(robot.Id);
                }

                input = reader.ReadLine();
            }

            string fakeId = reader.ReadLine();

            foreach (var item in list)
            {
                if (item.EndsWith(fakeId))
                {
                    writer.WriteLine(item);
                }
            }
        }
Example #2
0
        public static void Main(string[] args)
        {
            int            n       = int.Parse(Console.ReadLine());
            CitizenFactory factory = new CitizenFactory();
            List <Buyer>   buyers  = new List <Buyer>();

            for (int i = 0; i < n; i++)
            {
                string[] arr = Console.ReadLine().Split();

                factory.GetCitizen(arr, buyers);
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                foreach (var b in buyers)
                {
                    b.BuyFood(command);
                }

                command = Console.ReadLine();
            }
            Console.WriteLine(buyers.Sum(x => x.Food));
        }
Example #3
0
        public void Run()
        {
            int n = int.Parse(reader.ReadLine());

            for (int i = 0; i < n; i++)
            {
                Citizen citizen = null;
                Rebel   rebel   = null;

                string[] input = reader.ReadLine().Split();
                string   name  = input[0];

                if (input.Length == 4)
                {
                    citizen = citizenFactory.GetCitizen(input);
                    buyers.Add(citizen);
                }
                else if (input.Length == 3)
                {
                    rebel = rebelFactory.GetRebel(input);
                    buyers.Add(rebel);
                }
            }

            string inputName = reader.ReadLine();

            while (inputName != "End")
            {
                foreach (var person in buyers)
                {
                    if (person.Name == inputName)
                    {
                        person.BuyFood();
                    }
                }

                inputName = reader.ReadLine();
            }

            int totalFood = buyers.Sum(x => x.Food);

            writer.WriteLine(totalFood.ToString());
        }
Example #4
0
        public void Run()
        {
            string input = reader.ReadLine();

            while (input != "End")
            {
                string[] splitted = input.Split();

                string type = splitted[0];

                ICitizen citizen = null;
                IRobot   robot   = null;
                IPet     pet     = null;

                if (type == "Citizen")
                {
                    citizen = citizenFactory.GetCitizen(splitted);
                    list.Add(citizen.Birthdate);
                }
                else if (type == "Robot")
                {
                    robot = robotFactory.GetRobot(splitted);
                }
                else if (type == "Pet")
                {
                    pet = petFactory.GetPet(splitted);
                    list.Add(pet.Birthdate);
                }

                input = reader.ReadLine();
            }

            string year = reader.ReadLine();

            foreach (var item in list)
            {
                if (item.EndsWith(year))
                {
                    writer.WriteLine(item);
                }
            }
        }