Advertisement
Stan0033

Untitled

Jun 29th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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.  
  11.  
  12. static string Get() { return Console.ReadLine(); }
  13. static void Main()
  14. {
  15. bool Found = false;
  16. //"{firstName} {lastName} is {age} years old.".
  17. List<Student> StudentCurrent = new List<Student>();
  18. string TownRequires = string.Empty;
  19. while (true)
  20. {
  21. Found = false;
  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.  
  37. for (int i = 0; i < StudentCurrent.Count; i++)
  38. {
  39. if (StudentCurrent[i].FirstName == FName && StudentCurrent[i].LastName == LName && StudentCurrent[i].age < Age ) { StudentCurrent[i] = stud; Found = true ; break; }
  40.  
  41.  
  42. }
  43. if (!Found) { StudentCurrent.Add(stud); Found = false; }
  44. }
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57. foreach (Student s in StudentCurrent)
  58. {
  59. if (s.homeTown == TownRequires)
  60. {
  61. Console.WriteLine($"{s.FirstName } {s.LastName} is {s.age} years old.");
  62. }
  63. }
  64. }
  65.  
  66.  
  67. public class Student
  68. {
  69. public string FirstName { get; set; }
  70. public string LastName { get; set; }
  71. public int age { get; set; }
  72. public string homeTown { get; set; }
  73. }
  74.  
  75.  
  76. }
  77. }
  78.  
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement