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;
- namespace bat_try
- {
- class Program
- {
- struct Student
- {
- const int NUM_SEMESTER = 8;
- public string fio;
- public int grade;
- public int group;
- public double[] marks;
- public DateTime birthDate;
- public Student(string info)
- {
- marks = new double[NUM_SEMESTER];
- string[] formated = info.Split(new string[] { " | " }, StringSplitOptions.RemoveEmptyEntries);
- fio = formated[0];
- // Разбор даты
- birthDate = GetDateFromString(formated[1]);
- marks = GetArrayFromString(formated[2]);
- grade = Convert.ToByte(formated[3]);
- group = Convert.ToByte(formated[4]);
- }
- private static DateTime GetDateFromString(string date)
- {
- DateTime resultingDate;
- string[] dateString = date.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
- resultingDate =
- new DateTime(Convert.ToInt16(dateString[2]), Convert.ToInt16(dateString[1]), Convert.ToInt16(dateString[0]));
- return resultingDate;
- }
- private static double[] GetArrayFromString(string marks)
- {
- double[] result = new double[NUM_SEMESTER];
- string[] arrayString = marks.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < NUM_SEMESTER; ++i)
- {
- result[i] = Convert.ToDouble(arrayString[i]);
- }
- return result;
- }
- public void BinaryWrite(BinaryWriter BWriter)
- {
- BWriter.Write(this.fio);
- BWriter.Write(this.grade);
- BWriter.Write(this.group);
- for (int i = 0; i < NUM_SEMESTER; i++)
- {
- BWriter.Write(this.marks[i]);
- }
- BWriter.Write(this.birthDate.Day);
- BWriter.Write(this.birthDate.Month);
- BWriter.Write(this.birthDate.Year);
- }
- public void BinaryRead(BinaryReader BReader)
- {
- this.fio = BReader.ReadString();
- this.grade = BReader.ReadInt32();
- this.group = BReader.ReadInt32();
- this.marks = new double[NUM_SEMESTER];
- for (int i = 0; i < NUM_SEMESTER; i++)
- {
- this.marks[i] = BReader.ReadDouble();
- }
- this.birthDate = new DateTime(BReader.ReadInt32(), BReader.ReadInt32(), BReader.ReadInt32());
- }
- public void Print()
- {
- Console.Write(fio + ", {0}, ", birthDate.ToLongDateString());
- foreach (var cM in marks)
- Console.Write("{0} ", cM);
- Console.Write(", {0}, {1}\n", grade, group);
- }
- }
- public static void Main(string[] args)
- {
- string[] file = File.ReadAllLines("Students.txt");
- Student[] studs = new Student[file.Length];
- for (int i = 0; i < file.Length; ++i)
- studs[i] = new Student(file[i]);
- const string fileName = "Students.dat";
- BinaryWriter writer = new BinaryWriter(File.Open(fileName, FileMode.Append));
- foreach (var pStudent in studs)
- {
- pStudent.BinaryWrite(writer);
- pStudent.Print();
- }
- writer.Close();
- // Запись в бинарный файл окончена
- BinaryReader reader = new BinaryReader(File.Open(fileName, FileMode.Open));
- Student[] StudList = new Student[studs.Length];
- for (int i = 0; i < studs.Length; i++)
- {
- StudList[i].BinaryRead(reader);
- StudList[i].Print();
- }
- reader.Close();
- // Чтение из файла оконченно
- string[] LastNs = new string[StudList.Count()];
- for (int i = 0; i < StudList.Count(); i++)
- {
- string[] formated = StudList[i].fio.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
- LastNs[i] = formated[0];
- }
- bool similar = false;
- for (int i = 0; i < LastNs.Count(); i++)
- {
- if (LastNs[i] == "0")
- continue;
- for (int j = 0; j < LastNs.Count(); j++)
- {
- if (i == j)
- continue;
- if (LastNs[i] == LastNs[j])
- {
- similar = true;
- studs[j].Print();
- LastNs[j] = "0";
- }
- }
- if (similar == true)
- {
- studs[i].Print();
- LastNs[i] = "0";
- similar = false;
- }
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement