Advertisement
oshige_san

Untitled

May 13th, 2022
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 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=null;
  33.             System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  34.             if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  35.                 S = dlg.FileName;
  36.             if (S == null)
  37.                 return;
  38.            // FS = new FileStream("Список_студентов.txt", FileMode.Open);
  39.             using (StreamReader FI = new StreamReader(S))
  40.             {
  41.                 while ((S = FI.ReadLine()) != null)
  42.                 {
  43.                     string[] str = S.Split(';');
  44.                     Students.AddLast(new Student(str[0], str[1], str[2], str[3]));
  45.                 }
  46.             }
  47.             if (FS != null)
  48.                 FS.Dispose();
  49.                
  50.  
  51.  
  52.             Console.WriteLine("Cписок:");
  53.             foreach (Student St in Students)
  54.                 Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  55.  
  56.             Students.AddFirst(new Student("Бурлина", "Виктория", "Сергеевна", "жен1"));
  57.  
  58.             Students.AddLast(new Student("Юдаков", "Даниил", "Сергеевич", "м"));
  59.  
  60.             Students.AddBefore(Students.Last, new Student("Капсюлькин", "Данила", "Павлович", "мужской"));
  61.  
  62.             Students.Remove(Students.First.Next.Next);
  63.  
  64.             LinkedList<Student> NewStudents = new LinkedList<Student>(Students);
  65.             Students.Clear();
  66.  
  67.             Console.WriteLine("\n\nОкончательный список:");
  68.             foreach (Student St in NewStudents)
  69.                 Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  70.  
  71.             Console.WriteLine("\n\nВывести мальчиков(муж.) или девочек(жен.)?");
  72.             string Gend = Console.ReadLine();
  73.             int NFin;
  74.             string s1 = "муж";
  75.             int n1 = s1.Trim().Length;
  76.             string s2 = "жен";
  77.             if (Gend == "муж.")
  78.             {
  79.                 foreach (Student St in NewStudents)
  80.                 {
  81.                     if (n1 >= St.Gender.Trim().Length)
  82.                         NFin = St.Gender.Trim().Length;
  83.                     else
  84.                         NFin = n1;
  85.                     if (String.Compare(s1.Substring(0, NFin), St.Gender.Substring(0, NFin)) == 0)
  86.                         Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  87.                 }
  88.             }
  89.             else if (Gend == "жен.")
  90.             {
  91.                 foreach (Student St in NewStudents)
  92.                     if (String.Compare(s2.Substring(0, 3), St.Gender.Substring(0, 3)) == 0)
  93.                         Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
  94.             }
  95.             else
  96.                 Console.WriteLine("Студент такого пола не найден!");
  97.  
  98.  
  99.             Console.ReadKey();
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement