Advertisement
Infiniti_Inter

14 II

Nov 2nd, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. using System.IO;
  8.  
  9. namespace ConsoleApp1
  10. {
  11.  
  12.    
  13.     struct Student : IComparable<Student>
  14.     {
  15.         string fullName;
  16.         int yearOfBirth;
  17.         string adress;
  18.         int numberOfSchool;
  19.  
  20.      
  21.         public Student(string fullName, int yearOfBirth, string adress, int numberOfSchool)
  22.         {
  23.             this.fullName = fullName;
  24.             this.yearOfBirth = yearOfBirth;
  25.             this.adress = adress;
  26.             this.numberOfSchool = numberOfSchool;
  27.         }
  28.  
  29.         public int CompareTo(Student obj)
  30.         {
  31.             if (this.yearOfBirth > obj.yearOfBirth)
  32.                 return 1;
  33.             return -1;
  34.         }
  35.  
  36.         public string Show()
  37.         {
  38.             return string.Join(" ", fullName, yearOfBirth, adress, numberOfSchool);
  39.         }
  40.  
  41.         static public bool check(Student a, int nubmerOfSchool)
  42.         {
  43.             if (a.numberOfSchool == nubmerOfSchool)
  44.                 return true;
  45.             return false;
  46.         }
  47.         static public Student Copy(Student obj)
  48.         {
  49.            return new Student(obj.fullName, obj.yearOfBirth, obj.adress, obj.numberOfSchool);
  50.         }
  51.  
  52.     }
  53.     class Program
  54.     {
  55.  
  56.    
  57.         static void Print(Student[] array) //выводим данные на экран
  58.         {
  59.             using (StreamWriter output = new StreamWriter("d:/output.txt", false))
  60.             {
  61.                
  62.                 foreach (var item in array)
  63.                 {
  64.                     output.WriteLine(item.Show());
  65.                 }
  66.             }
  67.         }
  68.  
  69.         static void Main()
  70.         {
  71.             using (StreamReader input = new StreamReader("d:/input.txt"))
  72.             {
  73.                 int n = int.Parse(input.ReadLine());
  74.                 Student[] student = new Student[n];
  75.                 char[] sign = { ' ', '.', ',', ';', ':', '?', '!', '-' };
  76.                 for (int i = 0; i < n; ++i)
  77.                 {
  78.                     string[] line = input.ReadLine().Split(sign, StringSplitOptions.RemoveEmptyEntries);
  79.                     string name = string.Join(" ", line[0], line[1], line[2]);
  80.                     int year = int.Parse(line[3]);
  81.                     int schoolIn = int.Parse(line[line.Length - 1]);
  82.                     string adress = "";
  83.                     for (int j = 4; j < line.Length - 1; ++j)
  84.                         adress = string.Join(" ", adress, line[j]);
  85.                     student[i] = new Student(name, year, adress, schoolIn);
  86.                 }
  87.                 int school = int.Parse(input.ReadLine());
  88.                
  89.                 int cnt = 0;
  90.                 foreach (var q in student)
  91.                 {
  92.                     if (Student.check(q, school))
  93.                     {
  94.                         cnt++;
  95.                     }
  96.                 }
  97.                 Student[] studentsFromSchool = new Student[cnt];
  98.                 cnt = 0;
  99.                 foreach (var q in student)
  100.                 {
  101.                     if (Student.check(q, school))
  102.                     {
  103.                         studentsFromSchool[cnt] = Student.Copy(q);
  104.                         cnt++;
  105.                     }
  106.                 }
  107.  
  108.                 Array.Sort(studentsFromSchool);
  109.                 Print(studentsFromSchool);
  110.                 string LINE = new string('=', 100);
  111.                 Console.WriteLine(LINE);
  112.  
  113.                 /*
  114. 3
  115. A1 B C 2000 adwad,dawd wadwad #12 23
  116. A2 B C 1999 adwad,dawd wadwad #12 23
  117. A3 B C 2001 adwad,dawd wadwad #12 22
  118. 23
  119.                  */
  120.  
  121.             }
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement