Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>();

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

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

                if (tokens.Length == 4)
                {
                    string name      = tokens[0];
                    int    age       = int.Parse(tokens[1]);
                    string id        = tokens[2];
                    string birthdate = tokens[3];

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

                    buyers.Add(name, citizen);
                }
                else if (tokens.Length == 3)
                {
                    string name  = tokens[0];
                    int    age   = int.Parse(tokens[1]);
                    string group = tokens[2];

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

                    buyers.Add(name, rebel);
                }
            }

            int totalFood = 0;

            while (true)
            {
                string command = Console.ReadLine();

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

                if (buyers.Any(x => x.Key == command))
                {
                    totalFood += buyers[command].BuyFood();
                }
            }

            Console.WriteLine(totalFood);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            List <IBuyer> mammals = new List <IBuyer>();
            List <Robot>  robots  = new List <Robot>();

            int num        = int.Parse(Console.ReadLine());
            int boughtfood = 0;

            for (int i = 0; i < num; i++)
            {
                var data = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (data.Length == 3)
                {
                    string name  = data[0];
                    int    age   = int.Parse(data[1]);
                    string group = data[2];

                    IBuyer rebel = new Rebel(name, age, group);
                    mammals.Add(rebel);
                }
                else if (data.Length == 4)
                {
                    string name  = data[0];
                    int    age   = int.Parse(data[1]);
                    string id    = data[2];
                    string group = data[3];

                    IBuyer citizen = new Citizen(name, age, id, group);
                    mammals.Add(citizen);
                }
            }

            while (true)
            {
                string cmd = Console.ReadLine();

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

                for (int i = 0; i < mammals.Count; i++)
                {
                    if (mammals[i].Name == cmd)
                    {
                        boughtfood += mammals[i].BuyFood();
                    }
                }
            }

            Console.WriteLine(boughtfood);
        }
Ejemplo n.º 3
0
        static void Main()
        {
            List <IBuyer> buyers = new List <IBuyer>();

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

            for (int i = 0; i < inputCount; i++)
            {
                var entry = Console.ReadLine().Split().ToList();

                if (entry.Count == 4)
                {
                    Citizen citizen = new Citizen(entry[0], int.Parse(entry[1]), entry[2], entry[3]);
                    buyers.Add(citizen);
                }
                else
                {
                    Rebel rebel = new Rebel(entry[0], int.Parse(entry[1]), entry[2]);
                    buyers.Add(rebel);
                }
            }

            while (true)
            {
                string command = Console.ReadLine();

                if (command == "End")
                {
                    break;
                }
                else if (buyers.Any(x => x.Name == command))
                {
                    IBuyer buyer = buyers.FirstOrDefault(x => x.Name == command);

                    buyer.BuyFood();
                }
            }

            int totalFood = 0;

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

            Console.WriteLine(totalFood);
        }