private static int GetBoughtFood(List <IPerson> buyers)
        {
            string buyerName = String.Empty;

            while ((buyerName = Console.ReadLine()) != "End")
            {
                IPerson thisBuyer = buyers.FirstOrDefault(x => x.Name == buyerName);
                if (thisBuyer != null)
                {
                    thisBuyer.BuyFood();
                }
            }

            return(buyers.Sum(x => x.Food));
        }
Ejemplo n.º 2
0
        public static void Main()
        {
            int countOfPeople            = int.Parse(Console.ReadLine());
            ICollection <IPerson> buyers = new List <IPerson>();

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

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

            string name = Console.ReadLine();

            while (!name.Equals("End"))
            {
                if (buyers.Any(b => b.Name.Equals(name)))
                {
                    IPerson currentBuyer = buyers.FirstOrDefault(b => b.Name.Equals(name));
                    currentBuyer.BuyFood();
                }

                name = Console.ReadLine();
            }

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

            Console.WriteLine(totalFood);
        }