Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Security.Cryptography.X509Certificates;
- namespace classes
- {
- class Student
- {
- public string FirstName { get; set; }
- public string LasttName { get; set; }
- public int Age { get; set; }
- public string Hometown { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine().Split().ToArray();
- List<Student> list = new List<Student>();
- while (input[0] != "end")
- {
- string firstName = input[0];
- string lastName = input[1];
- int age = int.Parse(input[2]);
- string hometown = input[3];
- Student student = list.FirstOrDefault(x => x.FirstName == firstName && x.LasttName == lastName);
- if (student == null)
- {
- list.Add(new Student()
- {
- FirstName = firstName,
- LasttName = lastName,
- Age = age,
- Hometown = hometown
- });
- }
- else
- {
- student.FirstName = firstName;
- student.LasttName = lastName;
- student.Age = age;
- student.Hometown = hometown;
- }
- input = Console.ReadLine().Split().ToArray();
- }
- string last = Console.ReadLine();
- List<Student> filtered = list.Where(x => x.Hometown == last).ToList();
- foreach (var student in filtered)
- {
- Console.WriteLine($"{student.FirstName} { student.LasttName} is { student.Age } years old.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement