Esempio n. 1
0
        static void Main(string[] args)
        {
            //BorderControl
            //List<IIdentifiable> identifiables = new List<IIdentifiable>();

            //while (true)
            //{
            //    string input = Console.ReadLine();
            //    if (input == "End")
            //    {
            //        break;
            //    }

            //    string[] tokens = input.Split();

            //    if (tokens.Length == 2)
            //    {
            //        string model = tokens[0];
            //        string id = tokens[1];
            //        IIdentifiable robot = new Robot(model, id);
            //        identifiables.Add(robot);
            //    }
            //    else
            //    {
            //        string name = tokens[0];
            //        int age = int.Parse(tokens[1]);
            //        string id = tokens[2];
            //        IIdentifiable citizen = new Citizen(name, age, id);
            //        identifiables.Add(citizen);
            //    }
            //}

            //string fakeId = Console.ReadLine();

            //foreach (IIdentifiable identifiable in identifiables)
            //{
            //    if(identifiable.Id.EndsWith(fakeId))
            //    {
            //        Console.WriteLine(identifiable.Id);
            //    }
            //}

            //BirthdayCelebrations
            //List<IBirthable> birthables = new List<IBirthable>();

            //while (true)
            //{
            //    string input = Console.ReadLine();
            //    if (input == "End")
            //    {
            //        break;
            //    }

            //    string[] tokens = input.Split();
            //    string command = tokens[0];
            //    string name = tokens[1];

            //    if (command == "Pet")
            //    {
            //        string birthdate = tokens[2];
            //        IBirthable pet = new Pet(name, birthdate);
            //        birthables.Add(pet);
            //    }
            //    else if (command == "Citizen")
            //    {
            //        int age = int.Parse(tokens[2]);
            //        string id = tokens[3];
            //        string birthdate = tokens[4];

            //        IBirthable citizen = new Citizen(name, age, id, birthdate);
            //        birthables.Add(citizen);
            //    }

            //}

            //string year = Console.ReadLine();

            //foreach (var birthable in birthables)
            //{
            //    if (birthable.Birthdate.EndsWith(year))
            //    {
            //        Console.WriteLine(birthable.Birthdate);
            //    }
            //}

            //Food Shortage
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();
            int count = int.Parse(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                string   input  = Console.ReadLine();
                string[] tokens = input.Split();
                string   name   = tokens[0];
                int      age    = int.Parse(tokens[1]);

                if (tokens.Length == 4)
                {
                    string id        = tokens[2];
                    string birthdate = tokens[3];

                    IBuyer citizen = new Citizen(name, age, id, birthdate);
                    buyers.Add(name, citizen);
                }
                else
                {
                    string group = tokens[2];

                    IBuyer rebel = new Rebel(name, age, group);
                    buyers.Add(name, rebel);
                }
            }
            while (true)
            {
                string input = Console.ReadLine();

                if (input == "End")
                {
                    break;
                }

                if (buyers.ContainsKey(input))
                {
                    buyers[input].BuyFood();
                }
            }


            int totalFood = 0;

            foreach (var buyer in buyers)
            {
                totalFood += buyer.Value.Food;
            }

            Console.WriteLine(totalFood);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            List <Citizen> citizens = new List <Citizen>();

            List <Rebel> rebels = new List <Rebel>();



            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine();

                var command = input.Split(" ").ToArray();

                var citizenNames = citizens.Select(c => c.Name);
                var rebelNames   = rebels.Select(r => r.Name);


                if (command.Length == 4)
                {
                    string name = command[0];

                    if (!citizenNames.Contains(name) && !rebelNames.Contains(name))
                    {
                        int age = int.Parse(command[1]);

                        string id = command[2];

                        string birthdate = command[3];

                        Citizen citizen = new Citizen(name, age, id, birthdate);

                        citizens.Add(citizen);
                    }
                }
                else if (command.Length == 3)
                {
                    string name = command[0];

                    if (!citizenNames.Contains(name) && !rebelNames.Contains(name))
                    {
                        int age = int.Parse(command[1]);

                        string group = command[2];

                        Rebel rebel = new Rebel(name, age, group);

                        rebels.Add(rebel);
                    }
                }
            }

            var names = Console.ReadLine();

            while (names != "End")
            {
                var citizenNames = citizens.Select(c => c.Name);
                var rebelNames   = rebels.Select(r => r.Name);

                if (citizenNames.Contains(names))
                {
                    var citizen = citizens.FirstOrDefault(c => c.Name == names);

                    citizen.BuyFood();
                }
                else if (rebelNames.Contains(names))
                {
                    var rebel = rebels.FirstOrDefault(r => r.Name == names);

                    rebel.BuyFood();
                }

                names = Console.ReadLine();
            }

            var food = 0;

            foreach (var citizen in citizens)
            {
                food += citizen.Food;
            }

            foreach (var rebel in rebels)
            {
                food += rebel.Food;
            }

            Console.WriteLine(food);
        }