Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _5.Students__LAB
- {
- class Program
- {
- static void Main(string[] args)
- {
- string students = string.Empty;
- List<Student> savedStudentsInfo = new List<Student>();
- while ((students = Console.ReadLine()) != "end")
- {
- List<string> studentsInfo = students.Split().ToList();
- string firstNameOfStudent = studentsInfo[0];
- string secondNameOfStudent = studentsInfo[1];
- int ageOfStudent = int.Parse(studentsInfo[2]);
- string homeTownOfStudent = studentsInfo[3];
- Student student = new Student();
- student.firstName = firstNameOfStudent;
- student.lastName = secondNameOfStudent;
- student.age = ageOfStudent;
- student.hometown = homeTownOfStudent;
- if (IsStudentExicist(savedStudentsInfo, student.firstName, student.lastName))
- {
- if (GetStudent(savedStudentsInfo, student.firstName ,student.lastName))
- {
- }
- }
- else
- {
- savedStudentsInfo.Add(student);
- }
- }
- string inputStudents = Console.ReadLine();
- foreach (var town in savedStudentsInfo)
- {
- if (inputStudents == town.hometown)
- {
- Console.WriteLine($"{town.firstName} {town.lastName} is {town.age} years old.");
- }
- }
- }
- static bool IsStudentExicist(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;
- }
- }
- 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