Advertisement
Stan0033

Untitled

Jun 27th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. static int GetInt()
  11. {
  12. return int.Parse(Console.ReadLine());
  13. }
  14. static string Get() { return Console.ReadLine(); }
  15. static void Main()
  16. {
  17. //"{firstName} {lastName} is {age} years old.".
  18. List<Student> StudentCurrent = new List<Student>();
  19. string TownRequires = string.Empty;
  20. while (true)
  21. {
  22. string input = Get();
  23. if (input == "end") { TownRequires = Get(); break; }
  24. else
  25. {
  26. string[] parts = input.Split(' ').ToArray();
  27. string FName = parts[0];
  28. string LName = parts[1];
  29. int Age = Convert.ToInt32(parts[2]);
  30. string Town = parts[3];
  31. Student stud = new Student();
  32. stud.FirstName = FName;
  33. stud.LastName = LName;
  34. stud.age = Age;
  35. stud.homeTown = Town;
  36. StudentCurrent.Add(stud);
  37. }
  38. }
  39.  
  40.  
  41. List<Student> Filtered = new List<Student>();
  42. foreach (Student s in StudentCurrent)
  43. {
  44. if (s.homeTown == TownRequires)
  45. {
  46. Filtered.Add(s);
  47. }
  48.  
  49. }
  50. int[] MaxAge = new int[Filtered.Count];
  51. for (int i = 0; i < Filtered.Count; i++)
  52. {
  53. for (int x = i + 1; x < Filtered.Count; x++)
  54. {
  55. if (Filtered[i].FirstName == Filtered[x].FirstName && Filtered[i].LastName == Filtered[x].LastName)
  56. {
  57. if (Filtered[i].age >= Filtered[x].age)
  58. {
  59. MaxAge[i] = Filtered[i].age;
  60. } else { MaxAge[i] = Filtered[x].age; Filtered.RemoveAt(x); }
  61. }
  62.  
  63. }
  64.  
  65.  
  66. }
  67. foreach (Student s in Filtered)
  68. {
  69. Console.WriteLine($"{s.FirstName } {s.LastName} is {s.age} years old.");
  70. }
  71. }
  72. public class Student
  73. {
  74. public string FirstName { get; set; }
  75. public string LastName { get; set; }
  76. public int age { get; set; }
  77. public string homeTown { get; set; }
  78. }
  79.  
  80.  
  81. }
  82. }
  83.  
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement