static void Main(string[] args) { //// Problem 5 Border Controll //ICollection<IId> citicentsId = InitializeIdInCity(); //var faekIds = Console.ReadLine(); //PrintFakeCitizens(citicentsId, faekIds); //// Problem 6. Birthday Celebrations //ICollection<IBirthdate> birthdates = new List<IBirthdate>(); //birthdates = FillBirthdates(); //var yearToPrint = Console.ReadLine(); //PrintBorn(birthdates, yearToPrint); //Problem 7.Food Shortage ICollection <Human> foodBuyers = new List <Human>(); var peopleCount = int.Parse(Console.ReadLine()); for (int i = 0; i < peopleCount; i++) { var input = Console.ReadLine().Split(); if (input.Length == 4) { var citizen = new Citizen(input[0], int.Parse(input[1]), input[2]); foodBuyers.Add(citizen); } else if (input.Length == 3) { var rebel = new Rebel(input[0], int.Parse(input[1]), input[2]); foodBuyers.Add(rebel); } } var hungryPerson = ""; while ((hungryPerson = Console.ReadLine()) != "End") { var person = foodBuyers.FirstOrDefault(x => x.Name == hungryPerson); if (person != null) { person.BuyFood(); } } var foodBought = foodBuyers.Sum(x => x.Food); Console.WriteLine(foodBought); }
public void Run() { var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var args = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); IBuyer entity = null; if (args.Length == 4) { var parseDate = DateTime.ParseExact(args[3], "dd/MM/yyyy", CultureInfo.InvariantCulture); entity = new Citizen(args[0], int.Parse(args[1]), args[2], parseDate); } else if (args.Length == 3) { entity = new Rebel(args[0], int.Parse(args[1]), args[2]); } if (entity != null && !(this.names.Contains(args[0]))) { this.entities.Add(entity); this.names.Add(args[0]); } } while (true) { var Name = Console.ReadLine(); if (Name == "End") { break; } var entity = this.entities.Find(x => x.Name == Name); if (entity != null) { this.foodQuantity += entity.BuyFood(); } } Console.WriteLine(this.foodQuantity); }
public static void Main() { var n = int.Parse(Console.ReadLine()); var buyers = new Dictionary <string, IBuyer>(); for (var i = 0; i < n; i++) { var inputLine = Console.ReadLine(); var tokens = inputLine.Split(new[] { ' ' }); if (tokens.Length == 4) { var name = tokens[0]; var age = int.Parse(tokens[1]); var id = tokens[2]; var birthdate = tokens[3]; var currentCitizen = new Citizen(name, age, id, birthdate); buyers.Add(name, currentCitizen); } else if (tokens.Length == 3) { var name = tokens[0]; var age = int.Parse(tokens[1]); var group = tokens[2]; var currentRebel = new Rebel(name, age, group); buyers.Add(name, currentRebel); } } var currentBuyer = string.Empty; while ((currentBuyer = Console.ReadLine()) != "End") { if (buyers.ContainsKey(currentBuyer)) { buyers[currentBuyer].BuyFood(); } } var result = buyers.Select(x => x.Value.Food).Sum(); Console.WriteLine(result); //var inputLine = string.Empty; //var inhabitans = new List<IInhabitants>(); //var birthdaters = new List<IBornable>(); //while ((inputLine = Console.ReadLine())!= "End") //{ // var tokens = inputLine.Split(new[] {' '}); // if (tokens.Length == 5) // { // var name = tokens[1]; // var age = int.Parse(tokens[2]); // var id = tokens[3]; // var birthdate = tokens[4]; // var currentCitizen = new Citizen(name, age, id, birthdate); // inhabitans.Add(currentCitizen); // birthdaters.Add(currentCitizen); // } // else if(tokens.Length == 3) // { // var command = tokens[0]; // if (command == "Robot") // { // var model = tokens[1]; // var id = tokens[2]; // var currentRobot = new Robot(model, id); // inhabitans.Add(currentRobot); // } // else if (command == "Pet") // { // var name = tokens[1]; // var birthdate = tokens[2]; // var currentPet = new Pet(name, birthdate); // birthdaters.Add(currentPet); // } // } //} ////var fakeIds = Console.ReadLine(); ////var result = inhabitans //// .Where(x => x.Id.EndsWith(fakeIds)) //// .Select(x => x.Id) //// .ToArray(); ////Console.WriteLine(string.Join(Environment.NewLine, result)); //var birthYear = Console.ReadLine(); //var result = birthdaters // .Where(x => x.Birthdate.EndsWith(birthYear)) // .Select(x => x.Birthdate) // .ToArray(); //if (result.Length > 0) //{ // Console.WriteLine(string.Join(Environment.NewLine, result)); //} //else //{ // Console.WriteLine(); //} }