public void Run() { int n = int.Parse(reader.ReadLine()); for (int i = 0; i < n; i++) { string[] info = reader.ReadLine().Split(' ').ToArray(); if (info.Length == 4) { IBuyer citizen = new Human(info[0], int.Parse(info[1]), long.Parse(info[2]), info[3]); people.Add(citizen); } else { IBuyer rabel = new Rabel(info[0], int.Parse(info[1]), info[2]); people.Add(rabel); } } string input; while ((input = reader.ReadLine()) != GlobalConstants.END_INPUT) { string name = input; var person = people.FirstOrDefault(x => x.Name == name); if (person != null) { person.BuyFood(); } } writer.WriteLine(people.Sum(x => x.Food).ToString()); }
static void Main(string[] args) { List <Human> humans = new List <Human>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] humanInfo = Console.ReadLine().Split(' '); string name = humanInfo[0]; int age = int.Parse(humanInfo[1]); if (humanInfo.Length > 3) { string id = humanInfo[2]; string birthdate = humanInfo[3]; Citizen citizen = new Citizen(name, age, id, birthdate); humans.Add(citizen); } else { string group = humanInfo[2]; Rabel rebel = new Rabel(name, age, group); humans.Add(rebel); } } string byuer = Console.ReadLine(); int totalFood = 0; while (byuer != "End") { humans.Find(h => h.Name == byuer)?.BuyFood(); //if (humanByer!=null) //{ // humanByer.BuyFood(); //} byuer = Console.ReadLine(); } foreach (var human in humans) { totalFood += human.Food; } Console.WriteLine(totalFood); }
public static void Main() { var n = int.Parse(Console.ReadLine()); var buyers = new Dictionary <string, IBuyer>(); for (int i = 0; i < n; i++) { var tokens = Console.ReadLine().Split(); if (tokens.Length > 3) { var name = tokens[0]; var age = int.Parse(tokens[1]); var id = tokens[2]; var birthdate = tokens[3]; Citizen citizen = new Citizen(name, age, id, birthdate); buyers[name] = citizen; } else { var name = tokens[0]; var age = int.Parse(tokens[1]); var group = tokens[2]; Rabel rebel = new Rabel(name, age, group); buyers[name] = rebel; } } var buyerName = Console.ReadLine(); while (buyerName != "End") { if (buyers.ContainsKey(buyerName)) { buyers[buyerName].BuyFood(); } buyerName = Console.ReadLine(); } Console.WriteLine(buyers.Values.Sum(b => b.Food)); }
public static void Main() { List <IBuyer> statistic = new List <IBuyer>(); int parameter = int.Parse(Console.ReadLine()); for (int i = 0; i < parameter; i++) { string[] tokens = Console.ReadLine().Split(); string name = tokens[0]; if (tokens.Length == 4) { IBuyer citizen = new Citizens(name, int.Parse(tokens[1]), tokens[2], tokens[3]); statistic.Add(citizen); } else { IBuyer rabel = new Rabel(name, int.Parse(tokens[1]), tokens[2]); statistic.Add(rabel); } } string command; int result = 0; while ((command = Console.ReadLine()) != "End") { foreach (var person in statistic) { if (person.Name == command) { result += person.BuyFood(); } } } Console.WriteLine(result); }