Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- namespace Example
- {
- struct Transport : IComparable<Transport>
- {
- string Marka;
- string Number;
- string Famil;
- int Year;
- int Probeg;
- public Transport(string Marka, string Number, string Famil, int Year, int Probeg)
- {
- this.Marka = Marka;
- this.Number = Number;
- this.Famil = Famil;
- this.Year = Year;
- this.Probeg = Probeg;
- }
- public void Write(int k, StreamWriter file)
- {
- if (k >= this.Year)
- file.WriteLine(this);
- }
- public override string ToString() //Преобразование ToString()
- {
- return "" + Marka + " " + Number + " " + Famil + " " + Year.ToString() + " " + Probeg.ToString() + "";
- }
- public bool isNew(int currentYear)
- {
- return this.Year == currentYear;
- }
- public int CompareTo(Transport b) // сортировка
- {
- return this.Marka.CompareTo(b.Marka);
- }
- }
- class Program
- {
- static void Main()
- {
- string[] inpLine = null;
- using (StreamReader inFile = new StreamReader("D:/input.txt", Encoding.Default))
- {
- inpLine = inFile.ReadToEnd().Split('\n');
- }
- Transport[] trans = new Transport[inpLine.Length];
- for (int i = 0; i < inpLine.Length; i++)
- {
- string [] s = inpLine[i].Split();
- trans[i] = new Transport(s[0], s[1], s[2], Convert.ToInt32(s[3]), Convert.ToInt32(s[4]));
- }
- int currentYear = 2000;
- Array.Sort(trans);
- var res = from u in trans
- where u.isNew(currentYear)
- select u;
- using (StreamWriter fileOut = new StreamWriter("D:/output.txt"))
- {
- foreach (var v in res)
- fileOut.WriteLine(v);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement