using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Student
{
public string FullName { get; set; } // ФИО
public int BirthYear { get; set; } // Год рождения
public string Address { get; set; } // Домашний адрес
public string School { get; set; } // Какая школа окончена
}
class Program
{
static void Main()
{
string inputFile = "students.txt";
string outputFile = "filtered_students.txt";
Console.Write("Введите название школы для поиска: ");
string targetSchool = Console.ReadLine();
List<Student> students = new List<Student>();
using (StreamReader reader = new StreamReader(inputFile))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] parts = line.Split(';'); // разделитель - точка с запятой
Student s = new Student();
s.FullName = parts[0];
s.BirthYear = int.Parse(parts[1]);
s.Address = parts[2];
s.School = parts[3];
students.Add(s);
}
}
var filtered = students
.Where(s => s.School == targetSchool)
.OrderBy(s => s.BirthYear) // сортировка по году рождения (по возрастанию)
.ToList();
using (StreamWriter writer = new StreamWriter(outputFile))
{
writer.WriteLine("Студенты, окончившие школу: " + targetSchool);
writer.WriteLine("ФИО\t\tГод рождения\tАдрес\t\tШкола");
foreach (var s in filtered)
{
writer.WriteLine($"{s.FullName}\t{s.BirthYear}\t{s.Address}\t{s.School}");
}
}
Console.WriteLine("Готово. Результат в файле " + outputFile);
}
}
Козлова Дарья Алексеевна;2000;ул. Пушкина, 10;Школа №7
Смирнов Олег Иванович;1999;ул. Чехова, 3;Лицей №2
Васильева Мария Петровна;2001;ул. Лермонтова, 7;Школа №7