Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int          n      = int.Parse(Console.ReadLine());
            List <Human> humans = new List <Human>();
            List <Rebel> rebels = new List <Rebel>();

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

                if (input.Length == 4)
                {
                    Human human = new Human(input[0], int.Parse(input[1]), input[2], input[3]);
                    humans.Add(human);
                }
                else if (input.Length == 3)
                {
                    Rebel rebel = new Rebel(input[0], int.Parse(input[1]), input[2]);
                    rebels.Add(rebel);
                }
            }
            int totalFood = 0;

            string command = Console.ReadLine();

            while (command != "End")
            {
                foreach (var person in humans)
                {
                    if (person.Name == command)
                    {
                        totalFood += person.BuyFood(command);
                    }
                }
                foreach (var person in rebels)
                {
                    if (person.Name == command)
                    {
                        totalFood += person.BuyFood(command);
                    }
                }
                command = Console.ReadLine();
            }
            Console.WriteLine(totalFood);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int           peopleNum = int.Parse(Console.ReadLine());
            List <IBuyer> people    = new List <IBuyer>();

            for (int i = 0; i < peopleNum; i++)
            {
                string[] peopleInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   name       = peopleInfo[0];
                int      age        = int.Parse(peopleInfo[1]);

                if (peopleInfo.Length <= 3)
                {
                    string group = peopleInfo[2];
                    Rebel  rebel = new Rebel(name, age, group);
                    people.Add(rebel);
                }
                else
                {
                    string  id        = peopleInfo[2];
                    string  birthDate = peopleInfo[3];
                    Citizen citizen   = new Citizen(name, age, id, birthDate);
                    people.Add(citizen);
                }
            }

            string buyingPerson = Console.ReadLine();

            while (buyingPerson != "End")
            {
                var person = people.FirstOrDefault(x => x.Name == buyingPerson);
                if (person != null)
                {
                    person.BuyFood();
                }

                buyingPerson = Console.ReadLine();
            }

            int total = people.Sum(x => x.Food);

            Console.WriteLine(total);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            List <IBuyer> entities = new List <IBuyer>();
            int           n        = int.Parse(Console.ReadLine());
            string        input;

            for (int i = 0; i < n; i++)
            {
                IBuyer entity;
                input = Console.ReadLine();
                var elements = input.Split();
                if (elements.Length == 4)
                {
                    string name      = elements[0];
                    int    age       = int.Parse(elements[1]);
                    string id        = elements[2];
                    string birthdate = elements[3];

                    if (entities.Any(x => x.Name == name))
                    {
                        continue;
                    }
                    else
                    {
                        entity = new Citizen(name, age, id, birthdate);
                        entities.Add(entity);
                    }
                }
                else
                {
                    string name  = elements[0];
                    int    age   = int.Parse(elements[1]);
                    string group = elements[2];

                    if (entities.Any(x => x.Name == name))
                    {
                        continue;
                    }
                    else
                    {
                        entity = new Rebel(name, age, group);
                        entities.Add(entity);
                    }
                }
            }

            while ((input = Console.ReadLine()) != "End")
            {
                if (entities.Any(x => x.Name == input))
                {
                    var entity = entities.FirstOrDefault(x => x.Name == input);
                    entity.BuyFood();
                }
            }

            int totalFood = 0;

            foreach (var human in entities)
            {
                totalFood += human.Food;
            }

            Console.WriteLine(totalFood);
        }