using System.Text; namespace ConsoleApp1; //1 // internal class Program // { // static void Main(string[] args) // { // List entities = new List(); // // while (true) // { // string[] input = Console.ReadLine().Split(); // if (input[0] == "End") // { // break; // } // // if (input.Length == 2) // { // string model = input[0]; // string id = input[1]; // entities.Add(new Robot(model, id)); // } // else if (input.Length == 3) // { // string name = input[0]; // string age = input[1]; // string id = input[2]; // entities.Add(new Human(name, int.Parse(age), "", id)); // } // else // { // Console.WriteLine("Not valid"); // } // } // string fakeId = Console.ReadLine(); // foreach (var entity in entities) // { // if (fakeId != null && entity.IsFake(fakeId)) // { // Console.WriteLine(entity.Id); // } // } // } // } //2 // internal class Program // { // static void Main(string[] args) // { // List birthables = new List(); // while (true) // { // // string[] input = Console.ReadLine().Split(); // if (input[0] == "End") // { // break; // } // string type = input[0]; // if (type == "Robot") { } // else if (type == "Pet") // { // string name = input[1]; // string birthday = input[2]; // birthables.Add(new Pet(name, birthday)); // } // else if (type == "Citizen") // { // string name = input[1]; // int age = int.Parse(input[2]); // string id = input[3]; // string birthday = input[4]; // birthables.Add(new Human(name, age, birthday, id)); // } // } // string year = Console.ReadLine(); // foreach (var birthable in birthables) // { // if (year != null && birthable.IsBirthdayYear(year)) // { // Console.WriteLine(birthable.Birthday); // } // } // // } // } //3 internal class Program { static void Main(string[] args) { Dictionary buyers = new Dictionary(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] parts = Console.ReadLine().Split(); if (parts.Length == 4) { string name = parts[0]; int age = int.Parse(parts[1]); string id = parts[2]; string birthdate = parts[3]; buyers[name] = new Human(name, age, birthdate, id); } else if (parts.Length == 3) { string name = parts[0]; int age = int.Parse(parts[1]); string group = parts[2]; buyers[name] = new Rebel(name, age, group); } } while (true) { string name = Console.ReadLine(); if (name == "End") { break; } if (name != null && buyers.ContainsKey(name)) { buyers[name].BuyFood(); } } int totalFood = 0; foreach (var buyer in buyers.Values) { totalFood += buyer.Food; } Console.WriteLine(totalFood); } } public interface IRobot { public string Model { get; set; } public bool IsFake(string fakeIdInfo); } public interface IPet { public string Name { get; set; } } public interface IHuman { string Name { get; set; } int Age { get; set; } public bool IsFake(string fakeIdInfo); } public interface IBuyer { int Food { get; } void BuyFood(); } public interface IBirthable { string Birthday { get; } bool IsBirthdayYear(string year); } public class Robot : Entity, IRobot { public string Model { get; set; } public Robot(string model, string id) : base(id) { Model = model; } } public class Rebel : IBuyer { public string Name { get; set; } public int Age { get; set; } public string Group { get; set; } public int Food { get; private set; } public Rebel(string name, int age, string group) { Name = name; Age = age; Group = group; Food = 0; } public void BuyFood() { // Бунтовниците купуват по 5 храна Food += 5; } } public class Pet : IPet, IBirthable { public string Name { get; set; } public string Birthday { get; set; } public Pet(string name, string birthday) { Name = name; Birthday = birthday; } public bool IsBirthdayYear(string year) { if (Birthday.EndsWith(year)) { return true; } return false; } } public class Human : Entity, IHuman, IBirthable, IBuyer { public string Name { get; set; } public int Age { get; set; } public string Birthday { get; set; } public int Food { get; private set; } public Human(string name, int age, string birthday, string id) : base(id) { Name = name; Age = age; Birthday = birthday; Food = 0; } public bool IsBirthdayYear(string year) { if (Birthday.EndsWith(year)) { return true; } return false; } public void BuyFood() { Food += 10; } } public class Entity { public string Id {get; set;} public Entity(string id) { Id = id; } public bool IsFake(string fakeIdInfo) { if (Id.EndsWith(fakeIdInfo)) { return true; } return false; } }