Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Numerics;
- namespace fundamental14
- {
- class Student
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Age { get; set; }
- public string HomeTown { get; set; }
- }
- class MainClass
- {
- public static void Main()
- {
- List<Student> students = new List<Student>();
- string input;
- while ((input = Console.ReadLine()) != "end")
- {
- string[] data = input.Split();
- string firstName = data[0];
- string lastName = data[1];
- string age = data[2];
- string homeTown = data[3];
- if (IsStudentExisting(students, firstName, lastName))
- {
- Student student = GetStudent(students, firstName, lastName);
- student.FirstName = firstName;
- student.LastName = lastName;
- student.Age = age;
- student.HomeTown = homeTown;
- }
- else
- {
- Student student = new Student()
- {
- FirstName = firstName,
- LastName = lastName,
- Age = age,
- HomeTown = homeTown
- };
- students.Add(student);
- }
- }
- string city = Console.ReadLine();
- List<Student> filteredStudent = students.Where(s => s.HomeTown == city).ToList();
- foreach (Student student in filteredStudent)
- {
- Console.WriteLine("{0} {1} is {2} years old.", student.FirstName, student.LastName, student.Age);
- }
- }
- static bool IsStudentExisting(List<Student> students, string firstName, string lastName)
- {
- foreach (Student student in students)
- {
- if (student.FirstName == firstName && student.LastName == lastName)
- {
- return true;
- }
- }
- return false;
- }
- static Student GetStudent(List<Student> students, string firstName, string lastName)
- {
- Student existingStudent = null;
- foreach (Student student in students)
- {
- if (student.FirstName == firstName && student.LastName == lastName)
- {
- existingStudent = student;
- }
- }
- return existingStudent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement