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.Text;
- using System.Threading.Tasks;
- using System.Text.RegularExpressions;
- using System.IO;
- namespace ConsoleApp1
- {
- struct Student : IComparable<Student>
- {
- string fullName;
- int yearOfBirth;
- string adress;
- int numberOfSchool;
- public Student(string fullName, int yearOfBirth, string adress, int numberOfSchool)
- {
- this.fullName = fullName;
- this.yearOfBirth = yearOfBirth;
- this.adress = adress;
- this.numberOfSchool = numberOfSchool;
- }
- public int CompareTo(Student obj)
- {
- if (this.yearOfBirth > obj.yearOfBirth)
- return 1;
- return -1;
- }
- public string Show()
- {
- return string.Join(" ", fullName, yearOfBirth, adress, numberOfSchool);
- }
- static public bool check(Student a, int nubmerOfSchool)
- {
- if (a.numberOfSchool == nubmerOfSchool)
- return true;
- return false;
- }
- static public Student Copy(Student obj)
- {
- return new Student(obj.fullName, obj.yearOfBirth, obj.adress, obj.numberOfSchool);
- }
- }
- class Program
- {
- static void Print(Student[] array) //выводим данные на экран
- {
- using (StreamWriter output = new StreamWriter("d:/output.txt", false))
- {
- foreach (var item in array)
- {
- output.WriteLine(item.Show());
- }
- }
- }
- static void Main()
- {
- using (StreamReader input = new StreamReader("d:/input.txt"))
- {
- int n = int.Parse(input.ReadLine());
- Student[] student = new Student[n];
- char[] sign = { ' ', '.', ',', ';', ':', '?', '!', '-' };
- for (int i = 0; i < n; ++i)
- {
- string[] line = input.ReadLine().Split(sign, StringSplitOptions.RemoveEmptyEntries);
- string name = string.Join(" ", line[0], line[1], line[2]);
- int year = int.Parse(line[3]);
- int schoolIn = int.Parse(line[line.Length - 1]);
- string adress = "";
- for (int j = 4; j < line.Length - 1; ++j)
- adress = string.Join(" ", adress, line[j]);
- student[i] = new Student(name, year, adress, schoolIn);
- }
- int school = int.Parse(input.ReadLine());
- int cnt = 0;
- foreach (var q in student)
- {
- if (Student.check(q, school))
- {
- cnt++;
- }
- }
- Student[] studentsFromSchool = new Student[cnt];
- cnt = 0;
- foreach (var q in student)
- {
- if (Student.check(q, school))
- {
- studentsFromSchool[cnt] = Student.Copy(q);
- cnt++;
- }
- }
- Array.Sort(studentsFromSchool);
- Print(studentsFromSchool);
- string LINE = new string('=', 100);
- Console.WriteLine(LINE);
- /*
- 3
- A1 B C 2000 adwad,dawd wadwad #12 23
- A2 B C 1999 adwad,dawd wadwad #12 23
- A3 B C 2001 adwad,dawd wadwad #12 22
- 23
- */
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement