public static void Main() { List <IBuyer> people = new List <IBuyer>(); int number = int.Parse(Console.ReadLine()); for (int i = 0; i < number; i++) { string[] information = Console.ReadLine().Split(); if (information.Length == 4) { string name = information[0]; int age = int.Parse(information[1]); string id = information[2]; string birthdate = information[3]; IBuyer human = new Human(name, age, id, birthdate); people.Add(human); } else if (information.Length == 3) { string name = information[0]; int age = int.Parse(information[1]); string group = information[2]; IBuyer buyer = new Rebel(name, age, group); people.Add(buyer); } } string buyingFood = Console.ReadLine(); List <string> names = new List <string>(); while (buyingFood != "End") { names.Add(buyingFood); buyingFood = Console.ReadLine(); } foreach (var name in names) { if (people.Any(x => x.Name == name)) { IBuyer person = people.FirstOrDefault(x => x.Name == name); person.BuyFood(); } } int sumFood = 0; foreach (var person in people) { sumFood += person.Food; } Console.WriteLine(sumFood); }
static void Main(string[] args) { var humans = new List <Human>(); var n = int.Parse(Console.ReadLine()); var buyers = new HashSet <IBuyer>(); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(" ").ToArray(); if (input.Length == 4) { var name = input[0]; var age = int.Parse(input[1]); var id = input[2]; var birthdate = input[3]; var citizen = new Citizen(name, age, id, birthdate); humans.Add(citizen); } else { var name = input[0]; var age = int.Parse(input[1]); var group = input[2]; var rebel = new Rebel(name, age, group); humans.Add(rebel); } } var buyer = Console.ReadLine(); while (buyer != "End") { var currentBuyer = humans.FirstOrDefault(x => x.Name == buyer); if (currentBuyer != null) { currentBuyer.BuyFood(); buyers.Add(currentBuyer); } buyer = Console.ReadLine(); } var sum = 0; foreach (var client in buyers) { sum += client.Food; } Console.WriteLine(sum); }