Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- private static void Main()
- {
- // Читаем из файла
- string[] allLines = File.ReadAllLines("input.txt");
- // Преобразуем в массив студентов
- Student[] students = new Student[allLines.Length];
- for (int index = 0; index < allLines.Length; index++)
- {
- string line = allLines[index];
- string[] fields = line.Split(';');
- Student student = new Student(fields[0], fields[1], Convert.ToInt32(fields[2]),fields[3]);
- students[index] = student;
- }
- //Сортируем
- Array.Sort(students);
- // Выводим данные
- for (int i=0;i<students.Length;i++)
- {
- if (students[i].Mas.Contains("2"))
- {
- Console.WriteLine(students[i]);
- }
- }
- // Преобразуем в удобный для записи вид
- string[] linesToSave = new string[students.Length];
- for (int i = 0; i < students.Length; i++)
- {
- Student student = students[i];
- if (students[i].Mas.Contains("2"))
- {
- linesToSave[i] = student.ToString();
- }
- }
- // Сохраняем в файл
- File.WriteAllLines("output.txt", linesToSave);
- }
- }
- public struct Student : IComparable<Student>
- {
- public int CompareTo(Student obj)
- {
- if (Course > obj.Course)
- return 1;
- if (Course < obj.Course)
- return -1;
- else return 0;
- }
- public Student(string surname, string fac, int course, string mas)
- : this()
- {
- Surname = surname;
- Fac = fac;
- Course = course;
- Mas = mas;
- }
- // Фамилия
- public string Surname { get; private set; }
- // Факультет
- public string Fac { get; private set; }
- // Курс
- public int Course { get; private set; }
- // Оценки
- public string Mas { get ; private set; }
- public override string ToString()
- {
- return string.Format("{0}; {1}; {2}; {3}",
- Surname, Fac, Course, Mas);
- }
- }
- Петров ; Фак2; 211; 3 3 3 3 3;
- Сидоров; Фак3; 311; 2 4 5 2 4;
- Пупкин ; Фак4; 411; 4 3 4 3 4;
- Таратайкин ;Фак5; 511; 5 5 2 5 5;
- Иванов ; Фак1; 111; 2 3 4 4 5;
Advertisement
Add Comment
Please, Sign In to add comment