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.IO;
- using Microsoft.Win32;
- //using System
- namespace лаба_2_СПИСКИ
- {
- class Student
- {
- public string Name { get; set; }
- public string SurName { get; set; }
- public string MidName { get; set; }
- public string Gender { get; set; }
- public Student() { }
- public Student(string n, string sn, string mn, string g)
- { Name = n; SurName = sn; MidName = mn; Gender = g; }
- }
- class Program
- {
- [STAThread]
- static void Main(string[] args)
- {
- LinkedList<Student> Students = new LinkedList<Student>();
- FileStream FS = null;
- string S=null;
- System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
- if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- S = dlg.FileName;
- if (S == null)
- return;
- // FS = new FileStream("Список_студентов.txt", FileMode.Open);
- using (StreamReader FI = new StreamReader(S))
- {
- while ((S = FI.ReadLine()) != null)
- {
- string[] str = S.Split(';');
- Students.AddLast(new Student(str[0], str[1], str[2], str[3]));
- }
- }
- if (FS != null)
- FS.Dispose();
- Console.WriteLine("Cписок:");
- foreach (Student St in Students)
- Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
- Students.AddFirst(new Student("Бурлина", "Виктория", "Сергеевна", "жен1"));
- Students.AddLast(new Student("Юдаков", "Даниил", "Сергеевич", "м"));
- Students.AddBefore(Students.Last, new Student("Капсюлькин", "Данила", "Павлович", "мужской"));
- Students.Remove(Students.First.Next.Next);
- LinkedList<Student> NewStudents = new LinkedList<Student>(Students);
- Students.Clear();
- Console.WriteLine("\n\nОкончательный список:");
- foreach (Student St in NewStudents)
- Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
- Console.WriteLine("\n\nВывести мальчиков(муж.) или девочек(жен.)?");
- string Gend = Console.ReadLine();
- int NFin;
- string s1 = "муж";
- int n1 = s1.Trim().Length;
- string s2 = "жен";
- if (Gend == "муж.")
- {
- foreach (Student St in NewStudents)
- {
- if (n1 >= St.Gender.Trim().Length)
- NFin = St.Gender.Trim().Length;
- else
- NFin = n1;
- if (String.Compare(s1.Substring(0, NFin), St.Gender.Substring(0, NFin)) == 0)
- Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
- }
- }
- else if (Gend == "жен.")
- {
- foreach (Student St in NewStudents)
- if (String.Compare(s2.Substring(0, 3), St.Gender.Substring(0, 3)) == 0)
- Console.WriteLine("{0} {1} {2} {3}", St.Name, St.SurName, St.MidName, St.Gender);
- }
- else
- Console.WriteLine("Студент такого пола не найден!");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement