static void Main(string[] args) { List <IBuyer> buyers = new List <IBuyer>(); int numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { string[] info = Console.ReadLine().Split(); if (info.Length == 3) { IBuyer rebel = new Rebel(info[0], int.Parse(info[1]), info[2]); buyers.Add(rebel); } if (info.Length == 4) { IBuyer citizen = new Citizen(info[0], int.Parse(info[1]), info[2], info[3]); buyers.Add(citizen); } } string name = string.Empty; while ((name = Console.ReadLine()) != "End") { if (buyers.Any(b => b.Name == name)) { IBuyer buyer = buyers.FirstOrDefault(b => b.Name == name); buyer.BuyFood(); } } int totalFood = buyers.Sum(b => b.Food); Console.WriteLine(totalFood); }
public void Run(int numberOfPeople, List <IObject> objects) { for (int i = 0; i < numberOfPeople; i++) { string[] objectArgs = Console.ReadLine().Split(); string name = objectArgs[0]; int age = int.Parse(objectArgs[1]); if (objectArgs.Length == 4) { string id = objectArgs[2]; string birthdate = objectArgs[3]; var citizen = new Citizen(name, age, id, birthdate); objects.Add(citizen); } else { string group = objectArgs[2]; var rebel = new Rebel(name, age, group); objects.Add(rebel); } } }
private static IBuyer CreateRebel(List <IBuyer> buyerList, string[] data, string name, int age) { string group = data[2]; IBuyer rebel = new Rebel(name, age, group); buyerList.Add(rebel); return(rebel); }
public static void Main() { int n = int.Parse(Console.ReadLine()); var result = new Dictionary <string, IBuyer>(); for (int i = 0; i < n; i++) { string input = Console.ReadLine(); if (input == "End") { break; } string[] token = input.Split(' '); if (token.Length == 4) { string name = token[0]; int age = int.Parse(token[1]); string id = token[2]; var citizen = new Citizen(name, age, id); result.Add(name, citizen); } else if (token.Length == 3) { string name = token[0]; int age = int.Parse(token[1]); string group = token[2]; var rebel = new Rebel(name, age, group); result.Add(name, rebel); } } while (true) { string input = Console.ReadLine(); if (input == "End") { break; } if (result.ContainsKey(input)) { result[input].BuyFood(); } } Console.WriteLine(result.Sum(x => x.Value.Food)); }
static void Main(string[] args) { var rebels = new List <Rebel>(); var citizens = new List <Citizen>(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(); if (input.Length == 4) { var citizenName = input[0]; var citizenAge = int.Parse(input[1]); var id = input[2]; var birthDate = input[3]; var citizen = new Citizen(citizenName, citizenAge, id, birthDate); citizens.Add(citizen); } else { var rebelName = input[0]; var rebelAge = int.Parse(input[1]); var group = input[2]; var rebel = new Rebel(rebelName, rebelAge, group); rebels.Add(rebel); } } while (true) { var name = Console.ReadLine(); if (name == "End") { break; } if (rebels.Any(x => x.Name == name)) { var rebel = rebels.Where(x => x.Name == name).FirstOrDefault(); rebel.BuyFood(); } else if (citizens.Any(x => x.Name == name)) { var citizen = citizens.Where(x => x.Name == name).FirstOrDefault(); citizen.BuyFood(); } } var rebelsFood = rebels.Sum(x => x.Food); var citizensFood = citizens.Sum(x => x.Food); var totalFood = rebelsFood + citizensFood; Console.WriteLine(totalFood); }
private static Rebel CreateRebel(string[] rebelArgs) { string name = rebelArgs[0]; int age = int.Parse(rebelArgs[1]); string group = rebelArgs[2]; Rebel rebel = new Rebel(name, age, group); return(rebel); }
private void AddRebel(string[] commandArguments) { string name = commandArguments[0]; int age = int.Parse(commandArguments[1]); string group = commandArguments[2]; Rebel rebel = new Rebel(name, age, group); this.buyers.Add(rebel); }
public static void Main(string[] args) { List <Person> buyers = new List <Person>(); var numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { var peopleInformation = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var name = peopleInformation[0]; var age = int.Parse(peopleInformation[1]); try { if (peopleInformation.Length == 4) { var id = peopleInformation[2]; var birthdate = peopleInformation[3]; var citizen = new Citizen(name, age, id, birthdate); buyers.Add(citizen); } else if (peopleInformation.Length == 3) { var group = peopleInformation[2]; var rebel = new Rebel(name, age, group); buyers.Add(rebel); } } catch (ArgumentException exception) { Console.WriteLine(exception.Message); } } var command = Console.ReadLine(); while (command != "End") { var name = command.TrimEnd(); var currentbuyer = buyers.SingleOrDefault(x => x.Name == name); if (currentbuyer != null) { currentbuyer.BuyFood(); } command = Console.ReadLine(); } Console.WriteLine(buyers.Sum(b => b.Food)); }
static void Main(string[] args) { var destroyed = new List <IBuyer>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] command = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); if (command.Length == 4) { //Citizen string name = command[0]; int age = int.Parse(command[1]); string id = command[2]; string bithDate = command[3]; IBuyer currCitizen = new Citizen(name, age, id, bithDate); destroyed.Add(currCitizen); } else { //Rabel string name = command[0]; int age = int.Parse(command[1]); string group = command[2]; IBuyer currRabel = new Rebel(name, age, group); destroyed.Add(currRabel); } } int totalAmount = 0; while (true) { string command = Console.ReadLine(); if (command == "End") { break; } foreach (var curr in destroyed) { curr.BuyFood(command); } } foreach (var curr in destroyed) { totalAmount += curr.Food; } Console.WriteLine(totalAmount); }
private static void AddPerson(string[] personArgs, List <IPerson> people) { if (personArgs.Length == 4) { Citizen citizen = CreateCitizen(personArgs); people.Add(citizen); } else { Rebel rebel = CreateRebel(personArgs); people.Add(rebel); } }
public static void Main() { int N = int.Parse(Console.ReadLine()); List <IPerson> people = new List <IPerson>(); for (int i = 0; i < N; i++) { string[] peopleInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); string name = peopleInfo[0]; int age = int.Parse(peopleInfo[1]); if (peopleInfo.Length == 3) { // rebel string group = peopleInfo[2]; var rebel = new Rebel(name, age, group); people.Add(rebel); } else { // citizen string id = peopleInfo[2]; string birthdate = peopleInfo[3]; var citizen = new Citizen(name, age, id, birthdate); people.Add(citizen); } } while (true) { string name = Console.ReadLine(); if (name == "End") { break; } var person = people.FirstOrDefault(d => d.Name == name); if (person != null) { (person as IBuyer).BuyFood(); } } int totalFood = 0; foreach (var item in people) { totalFood += (item as IBuyer).Food; } Console.WriteLine(totalFood); }
static void Main(string[] args) { Citizen citizensList = new Citizen(); Rebel rebelsList = new Rebel(); Citizen citizen = new Citizen(); Rebel rebel = new Rebel(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(); if (input.Length == 4) { citizen = new Citizen(input[0], int.Parse(input[1]), input[2], input[3]); citizensList.citizens.Add(citizen); } else { rebel = new Rebel(input[0], int.Parse(input[1]), input[2]); rebelsList.rebels.Add(rebel); } } string line = Console.ReadLine(); while (line != "End") { for (int i = 0; i < citizensList.citizens.Count; i++) { if (citizensList.citizens[i].name == line) { citizen.BuyFood(); } } for (int i = 0; i < rebelsList.rebels.Count; i++) { if (rebelsList.rebels[i].name == line) { rebel.BuyFood(); } } line = Console.ReadLine(); } Console.WriteLine((citizen.Food) + (rebel.Food)); }
public static void Main() { List <IBuyer> buyers = new List <IBuyer>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); if (input.Length == 4) { string name = input[0]; string age = input[1]; string id = input[2]; string birthdate = input[3]; Citizen citizen = new Citizen(name, age, id, birthdate); buyers.Add(citizen); } else if (input.Length == 3) { string name = input[0]; string age = input[1]; string group = input[2]; Rebel rebel = new Rebel(name, age, group); buyers.Add(rebel); } } while (true) { string name = Console.ReadLine(); if (name == "End") { break; } var buyer = buyers.SingleOrDefault(b => b.Name == name); if (buyer != null) { buyer.BuyFood(); } } Console.WriteLine(buyers.Sum(x => x.Food)); }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <IBuyer> buyers = new List <IBuyer>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(); string name = input[0]; int age = int.Parse(input[1]); if (input.Length > 3) { string id = input[2]; string birthdate = input[3]; IBuyer citizen = new Citizen(name, age, id, birthdate); buyers.Add(citizen); } else { string group = input[2]; IBuyer rebel = new Rebel(name, age, group); buyers.Add(rebel); } } string buyerName = Console.ReadLine(); int totalFood = 0; while (buyerName != "End") { foreach (var buyer in buyers) { if (buyer.Name == buyerName) { buyer.BuyFood(); } } buyerName = Console.ReadLine(); } foreach (var buyer in buyers) { totalFood += buyer.Food; } Console.WriteLine(totalFood); }
public static void Main(string[] args) { HashSet <IBuyer> creatures = new HashSet <IBuyer>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string inputCreature = Console.ReadLine(); string[] creatureInfo = inputCreature.Split(); string name = creatureInfo[0]; int age = int.Parse(creatureInfo[1]); if (creatureInfo.Length == 4) { string id = creatureInfo[2]; string birthdate = creatureInfo[3]; IBuyer creature = new Citizen(name, age, id, birthdate); creatures.Add(creature); } else if (creatureInfo.Length == 3) { string group = creatureInfo[2]; IBuyer creature = new Rebel(name, age, group); creatures.Add(creature); } } string input = Console.ReadLine(); int foodSum = 0; while (input != "End") { IBuyer targetCitizen = creatures.FirstOrDefault(c => c.Name == input); if (targetCitizen != null) { foodSum += targetCitizen.BuyFood(); } input = Console.ReadLine(); } Console.WriteLine(foodSum); }
static void Main(string[] args) { Dictionary <string, IBuyer> buyersByName = new Dictionary <string, IBuyer>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] parts = Console.ReadLine().Split(); if (parts.Length == 3) { string name = parts[0]; int age = int.Parse(parts[1]); string group = parts[2]; buyersByName[name] = new Rebel(name, age, group); } else { string name = parts[0]; int age = int.Parse(parts[1]); string id = parts[2]; string birthdate = parts[3]; buyersByName[name] = new Citizen(name, age, birthdate, id); } } while (true) { string line = Console.ReadLine(); if (line == "End") { break; } if (!buyersByName.ContainsKey(line)) { continue; } IBuyer buyer = buyersByName[line]; buyer.BuyFood(); } var total = buyersByName.Values.Sum(b => b.Food); Console.WriteLine(total); }
static void Main(string[] args) { List <IBuyer> buyers = new List <IBuyer>(); int numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { var input = Console.ReadLine().Split(); if (input.Length == 4) { string name = input[0]; int age = int.Parse(input[1]); string id = input[2]; string birthdate = input[3]; Citizen citizen = new Citizen(name, age, id, birthdate); buyers.Add(citizen); } else if (input.Length == 3) { string name = input[0]; int age = int.Parse(input[1]); string group = input[2]; Rebel rebel = new Rebel(name, age, group); buyers.Add(rebel); } } string command = Console.ReadLine(); while (command != "End") { string name = command; var buyer = buyers.SingleOrDefault(b => b.Name == name); if (buyer != null) { buyer.BuyFood(); } command = Console.ReadLine(); } Console.WriteLine(buyers.Sum(b => b.Food)); }
static void Main(string[] args) { var people = new List <IBuyer>(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var inputTokens = Console.ReadLine().Split(); if (inputTokens.Length == 4) { var name = inputTokens[0]; var age = int.Parse(inputTokens[1]); var id = inputTokens[2]; var birthdate = inputTokens[3]; IBuyer citizen = new Citizen(name, age, id, birthdate); people.Add(citizen); } else if (inputTokens.Length == 3) { var name = inputTokens[0]; var age = int.Parse(inputTokens[1]); var group = inputTokens[2]; IBuyer rebel = new Rebel(name, age, group); people.Add(rebel); } } string input; while ((input = Console.ReadLine()) != "End") { var name = input; foreach (var buyer in people) { if (buyer.Name == name) { buyer.BuyFood(); break; } } } var totalFood = people.Sum(x => x.Food); Console.WriteLine(totalFood); }
public void Run() { var numberOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfPeople; i++) { var command = Console.ReadLine().Split(); if (command.Length == 4) { var name = command[0]; var age = int.Parse(command[1]); var id = command[2]; var birthdate = command[3]; var currCitizen = new Citizen(name, age, id, birthdate); people.Add(currCitizen); } else if (command.Length == 3) { var name = command[0]; var age = int.Parse(command[1]); var group = command[2]; var currRebel = new Rebel(name, age, group); people.Add(currRebel); } } while (true) { var command = Console.ReadLine(); if (command == "End") { break; } else { if (people.Any(x => x.Name == command)) { var person = people.FirstOrDefault(x => x.Name == command); person.BuyFood(); } } } Console.WriteLine(people.Sum(x => x.Food)); }
static void Main(string[] args) { var count = int.Parse(Console.ReadLine()); List <Person> people = new List <Person>(); for (int i = 0; i < count; i++) { var input = Console.ReadLine().Split(); if (input.Length == 4) { var name = input[0]; var age = int.Parse(input[1]); var id = input[2]; var birthday = input[3]; var person = new Citizen(name, age, id, birthday); people.Add(person); } else if (input.Length == 3) { var name = input[0]; var age = int.Parse(input[1]); var group = input[2]; var rebel = new Rebel(name, age, group); people.Add(rebel); } } while (true) { var name = Console.ReadLine(); if (name == "End") { break; } var indexOfPerson = people.FindIndex(x => x.Name == name); if (indexOfPerson != -1) { people[indexOfPerson].BuyFood(); } } var totalAmountOfFood = people.Select(x => x.Food).Sum(); Console.WriteLine(totalAmountOfFood); }
static void Main(string[] args) { Dictionary <string, IBuyer> buyerByName = new Dictionary <string, IBuyer>(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine().Split(); var name = input[0]; var age = int.Parse(input[1]); if (input.Length == 3) { var group = input[2]; buyerByName[name] = new Rebel(name, age, group); } else { var id = input[2]; var birthDate = input[3]; buyerByName[name] = new Citizen(name, age, id, birthDate); } } while (true) { var input = Console.ReadLine(); if (input == "End") { break; } if (buyerByName.ContainsKey(input)) { buyerByName[input].BuyFood(); } } var totalFood = buyerByName.Values.Sum(f => f.Food); Console.WriteLine(totalFood); }
public static void Main(string[] args) { List <IBuyer> collection = new List <IBuyer>(); int peopleNumber = int.Parse(Console.ReadLine()); for (int i = 0; i < peopleNumber; i++) { string input = Console.ReadLine(); string[] splitedInput = input.Split(); if (splitedInput.Length == 4) { string name = splitedInput[0]; string age = splitedInput[1]; string id = splitedInput[2]; string birthdate = splitedInput[3]; Citizen citizen = new Citizen(name, age, id, birthdate); collection.Add(citizen); } else if (splitedInput.Length == 3) { string name = splitedInput[0]; string age = splitedInput[1]; string groupe = splitedInput[2]; Rebel rebel = new Rebel(name, age, groupe); collection.Add(rebel); } } while (true) { string name = Console.ReadLine(); if (name == "End") { break; } var buyer = collection.SingleOrDefault(b => b.Name == name); if (buyer != null) { buyer.BuyFood(); } } Console.WriteLine(collection.Sum(b => b.Food)); }
static void Main(string[] args) { Citizen citizen = new Citizen("s", 2, "s", "s"); int n = int.Parse(Console.ReadLine()); Dictionary <string, IBuyer> buyers = new Dictionary <string, IBuyer>(); for (int i = 0; i < n; i++) { string[] cmdArgs = Console.ReadLine().Split(); if (cmdArgs.Length == 3) { string name = cmdArgs[0]; int age = int.Parse(cmdArgs[1]); string group = cmdArgs[2]; IBuyer buyer = new Rebel(name, age, group); buyers.Add(name, buyer); } else { string name = cmdArgs[0]; int age = int.Parse(cmdArgs[1]); string id = cmdArgs[2]; string birthdate = cmdArgs[3]; IBuyer buyer = new Citizen(name, age, id, birthdate); buyers.Add(name, buyer); } } string input; while ((input = Console.ReadLine()) != "End") { string name = input; if (buyers.ContainsKey(name)) { buyers[name].BuyFood(); } } int boughtFood = buyers.Sum(b => b.Value.Food); Console.WriteLine(boughtFood); }
private static void Main() { int n = int.Parse(Console.ReadLine()); List <IBuyer> people = new List <IBuyer>(); for (int i = 0; i < n; i++) { string[] items = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string name = items[0]; int age = int.Parse(items[1]); if (items.Length == 3) { string group = items[2]; Rebel rebel = new Rebel(name, age, group); people.Add(rebel); } else if (items.Length == 4) { string id = items[2]; string birthdate = items[3]; Citizen citizen = new Citizen(name, age, id, birthdate); people.Add(citizen); } } string person = Console.ReadLine(); while (person != "End") { if (people.FirstOrDefault(p => p.Name == person) != null) { people.FirstOrDefault(p => p.Name == person).BuyFood(); } person = Console.ReadLine(); } Console.WriteLine(people.Sum(p => p.Food)); }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <IBuyer> people = new List <IBuyer>(); Citizen citizen = null; Rebel rebel = null; for (int i = 0; i < n; i++) { var tokens = Console.ReadLine().Split(); string name = tokens[0]; if (tokens.Length == 4) { citizen = new Citizen(name); people.Add(citizen); } else if (tokens.Length == 3) { rebel = new Rebel(name); people.Add(rebel); } } string command = Console.ReadLine(); while (command != "End") { if (people.Any(x => x.Name == command)) { people.First(x => x.Name == command).BuyFood(); } command = Console.ReadLine(); } int sum = 0; foreach (var item in people) { sum += item.Food; } Console.WriteLine(sum); }
static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); List <IBuy> listOfPerson = new List <IBuy>(); for (int i = 1; i <= number; i++) { string[] data = Console.ReadLine() .Split(); string name = data[0]; int age = int.Parse(data[1]); if (data.Length == 4) { string id = data[2]; string birthdate = data[3]; IBuy citizen = new Citizen(name, age, id, birthdate); listOfPerson.Add(citizen); } else if (data.Length == 3) { string group = data[2]; IBuy rebel = new Rebel(name, age, group); listOfPerson.Add(rebel); } } string input = string.Empty; while ((input = Console.ReadLine()) != "End") { foreach (var person in listOfPerson) { if (person.Name == input) { person.BuyFood(); } } } int total = 0; foreach (var person in listOfPerson) { total += person.Food; } Console.WriteLine(total); }
public void Run() { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] inputArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); if (inputArgs.Length == 4) { string name = inputArgs[0]; int age = int.Parse(inputArgs[1]); string id = inputArgs[2]; string birthdate = inputArgs[3]; IBuyer citizen = new Citizen(name, age, id, birthdate); this.people.Add(citizen); } else { string name = inputArgs[0]; int age = int.Parse(inputArgs[1]); string group = inputArgs[2]; IBuyer rebel = new Rebel(name, age, group); this.people.Add(rebel); } } string person = string.Empty; while ((person = Console.ReadLine()) != "End") { if (people.FirstOrDefault(x => x.Name == person) != null) { people.FirstOrDefault(x => x.Name == person).BuyFood(); } } Console.WriteLine(people.Sum(x => x.Food)); }
public static void Main() { List <IIdentifyableBuyer> buyers = new List <IIdentifyableBuyer>(); int numbOfPeople = int.Parse(Console.ReadLine()); for (int i = 0; i < numbOfPeople; i++) { string[] cmdArgs = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); switch (cmdArgs.Length) { case 3: var rebel = new Rebel(cmdArgs[0], int.Parse(cmdArgs[1]), cmdArgs[2]); buyers.Add(rebel); break; case 4: var citizen = new Citizen(cmdArgs[0], int.Parse(cmdArgs[1]), cmdArgs[2], cmdArgs[3]); buyers.Add(citizen); break; } } int totalFood = 0; while (true) { string cmd = Console.ReadLine(); if (cmd == "End") { break; } string name = cmd; var buyer = buyers.Find(b => b.Name == name); if (buyer != null) { totalFood += buyer.BuyFood(); } } Console.WriteLine(totalFood); }
static void Main(string[] args) { var list = new List <IBuyer>(); int numberOfLines = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfLines; i++) { var token = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); if (token.Length == 4) { var name = token[0]; var age = int.Parse(token[1]); var id = token[2]; var birthdate = DateTime.ParseExact(token[3], "dd/MM/yyyy", CultureInfo.InvariantCulture); Citizen citizen = new Citizen(name, age, id, birthdate); list.Add(citizen); } else if (token.Length == 3) { var rebelName = token[0]; var rebelAge = int.Parse(token[1]); var rebelGroup = token[2]; Rebel rebel = new Rebel(rebelName, rebelAge, rebelGroup); list.Add(rebel); } } var nameOfPerson = Console.ReadLine(); while (nameOfPerson != "End") { foreach (var person in list) { if (person.Name == nameOfPerson) { person.BuyFood(); } } nameOfPerson = Console.ReadLine(); } Console.WriteLine(list.Sum(l => l.Food)); }
public static void Main(string[] args) { var numberOfBuyers = int.Parse(Console.ReadLine()); List <IBuyer> buyers = new List <IBuyer>(); for (int i = 0; i < numberOfBuyers; i++) { var tokens = Console.ReadLine().Split(); var name = tokens[0]; var age = int.Parse(tokens[1]); if (tokens.Length == 3) { Rebel rebel = new Rebel(name, age, tokens[2]); buyers.Add(rebel); } else { Citizen citizen = new Citizen(name, age, tokens[2], tokens[3]); buyers.Add(citizen); } } var input = Console.ReadLine(); while (input != "End") { var currentBuyer = buyers.FirstOrDefault(x => x.Name == input); if (currentBuyer != null) { currentBuyer.BuyFood(); } input = Console.ReadLine(); } Console.WriteLine(buyers.Select(x => x.Food).Sum()); }