Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static int GetInt()
- {
- return int.Parse(Console.ReadLine());
- }
- static string Get() { return Console.ReadLine(); }
- static void Main()
- {
- //"{firstName} {lastName} is {age} years old.".
- List<Student> StudentCurrent = new List<Student>();
- string TownRequires = string.Empty;
- while (true)
- {
- string input = Get();
- if (input == "end") { TownRequires = Get(); break; }
- else
- {
- string[] parts = input.Split(' ').ToArray();
- string FName = parts[0];
- string LName = parts[1];
- int Age = Convert.ToInt32(parts[2]);
- string Town = parts[3];
- Student stud = new Student();
- stud.FirstName = FName;
- stud.LastName = LName;
- stud.age = Age;
- stud.homeTown = Town;
- StudentCurrent.Add(stud);
- }
- }
- List<Student> Filtered = new List<Student>();
- foreach (Student s in StudentCurrent)
- {
- if (s.homeTown == TownRequires)
- {
- Filtered.Add(s);
- }
- }
- int[] MaxAge = new int[Filtered.Count];
- for (int i = 0; i < Filtered.Count; i++)
- {
- for (int x = i + 1; x < Filtered.Count; x++)
- {
- if (Filtered[i].FirstName == Filtered[x].FirstName && Filtered[i].LastName == Filtered[x].LastName)
- {
- if (Filtered[i].age >= Filtered[x].age)
- {
- MaxAge[i] = Filtered[i].age;
- } else { MaxAge[i] = Filtered[x].age; Filtered.RemoveAt(x); }
- }
- }
- }
- foreach (Student s in Filtered)
- {
- Console.WriteLine($"{s.FirstName } {s.LastName} is {s.age} years old.");
- }
- }
- public class Student
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public int age { get; set; }
- public string homeTown { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement