oshige_san

Untitled

May 9th, 2022
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 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.IO;
  7. using Microsoft.Win32;
  8. //using System
  9.  
  10. namespace лаба_2_СПИСКИ
  11. {
  12.  
  13.     class Student
  14.     {
  15.         public string Name { get; set; }
  16.         public string SurName { get; set; }
  17.         public string MidName { get; set; }
  18.         public string Gender { get; set; }
  19.         public Student() { }
  20.         public Student(string n, string sn, string mn, string g)
  21.         { Name = n; SurName = sn; MidName = mn; Gender = g; }
  22.  
  23.     }
  24.     class Program
  25.     {
  26.         [STAThread]
  27.         static void Main(string[] args)
  28.         {
  29.  
  30.             LinkedList<Student> Students = new LinkedList<Student>();
  31.             FileStream FS = null;
  32.             string S;
  33.             FS = new FileStream("Список_студентов.txt", FileMode.Open);
  34.             using (StreamReader FI = new StreamReader(FS))
  35.             {
  36.                 while ((S = FI.ReadLine()) != null)
  37.                 {
  38.                     string[] str = S.Split(';');
  39.                     Students.AddLast(new Student(str[0], str[1], str[2], str[3]));
  40.                 }
  41.             }
  42.             if (FS != null)
  43.                 FS.Dispose();
  44.                
  45.  
  46.            // OpenFileDialog dlg = new OpenFileDialog();
  47.  
  48.             Console.WriteLine("Cписок:");
  49.             foreach (Student St in Students)
  50.                 Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  51.  
  52.             Students.AddFirst(new Student("Бурлина", "Виктория", "Сергеевна", "жен1"));
  53.  
  54.             Students.AddLast(new Student("Юдаков", "Даниил", "Сергеевич", "м"));
  55.  
  56.             Students.AddBefore(Students.Last, new Student("Капсюлькин", "Данила", "Павлович", "мужской"));
  57.  
  58.             Students.Remove(Students.First.Next.Next);
  59.  
  60.             LinkedList<Student> NewStudents = new LinkedList<Student>(Students);
  61.             Students.Clear();
  62.  
  63.             Console.WriteLine("\n\nОкончательный список:");
  64.             foreach (Student St in NewStudents)
  65.                 Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  66.  
  67.             Console.WriteLine("\n\nВывести мальчиков(муж.) или девочек(жен.)?");
  68.             string Gend = Console.ReadLine();
  69.             int NFin;
  70.             string s1 = "муж";
  71.             int n1 = s1.Trim().Length;
  72.             string s2 = "жен";
  73.             if (Gend == "муж.")
  74.             {
  75.                 foreach (Student St in NewStudents)
  76.                 {
  77.                     if (n1 >= St.Gender.Trim().Length)
  78.                         NFin = St.Gender.Trim().Length;
  79.                     else
  80.                         NFin = n1;
  81.                     if (String.Compare(s1.Substring(0, NFin), St.Gender.Substring(0, NFin)) == 0)
  82.                         Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  83.                 }
  84.             }
  85.             else if (Gend == "жен.")
  86.             {
  87.                 foreach (Student St in NewStudents)
  88.                     if (String.Compare(s2.Substring(0, 3), St.Gender.Substring(0, 3)) == 0)
  89.                         Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  90.             }
  91.             else
  92.                 Console.WriteLine("Студент такого пола не найден!");
  93.  
  94.  
  95.             Console.ReadKey();
  96.         }
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment