Advertisement
Ochkasty_Dino

Practicum15-II-5

Dec 15th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.IO;
  5.  
  6. namespace pr._15.II._3
  7. {
  8.     class passanger
  9.     {
  10.         string f, i, o;
  11.         public int kol, ves;
  12.  
  13.         public passanger(string f, string i, string o, int kol, int ves)
  14.         {
  15.             this.f = f;
  16.             this.i = i;
  17.             this.o = o;
  18.             this.kol = kol;
  19.             this.ves = ves;
  20.         }
  21.  
  22.         public void show()
  23.         {
  24.             Console.WriteLine("^{0} {1} {2}, количество вещей равно {3}, общий вес вещей равен {4}", f, i, o, kol, ves);
  25.  
  26.         }
  27.         public void show(StreamWriter fileout)
  28.         {
  29.             fileout.WriteLine("^{0} {1} {2}, количество вещей равно {3}, общий вес вещей равен {4}", f, i, o, kol, ves);
  30.  
  31.         }
  32.  
  33.         public int kolich
  34.         {
  35.             get { return kol; }
  36.         }
  37.  
  38.         public int Session
  39.         {
  40.             get { return ves; }
  41.         }
  42.     }
  43.  
  44.     class Program
  45.     {
  46.  
  47.  
  48.         static passanger[] Input()
  49.         {
  50.             int n = File.ReadAllLines("C:/Users/belousaa/Documents/in1.txt").Length;
  51.             passanger[] sArray = new passanger[n];
  52.             using (StreamReader filein = new StreamReader("C:/Users/belousaa/Documents/in1.txt", Encoding.GetEncoding(1251)))
  53.             {
  54.                 for (int i = 0; i < n; i++)
  55.                 {
  56.                     // считываемая строка
  57.                     string[] str = filein.ReadLine().Split(' ');
  58.                     sArray[i] = new passanger(str[0], str[1], str[2], int.Parse(str[3]), int.Parse(str[4]));
  59.                 }
  60.             }
  61.             return sArray;
  62.         }
  63.  
  64.  
  65.  
  66.         static void Main(string[] args)
  67.         {
  68.             passanger[] passangers = Input();
  69.             Console.WriteLine("Введите минимальный вес: ");
  70.             int xves = int.Parse(Console.ReadLine());
  71.  
  72.             // 1 способ
  73.             // описание запроса
  74.             var gpas =
  75.                 from n in passangers
  76.                 where (n.ves > xves)
  77.                 orderby n.kolich
  78.                 select n;
  79.  
  80.             using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output1.txt"))
  81.             {
  82.                 fileout.WriteLine("Подходящие пассажиры: ");
  83.                 foreach (var x in gpas)
  84.                 {
  85.                     x.show(fileout);
  86.                 }
  87.             }
  88.  
  89.  
  90.             // 2 способ
  91.             // описание запроса
  92.             var gpass = passangers.Where(n => (n.ves > xves)).OrderBy(n => n.kolich);
  93.  
  94.             using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output2.txt"))
  95.             {
  96.                 fileout.WriteLine("Подходящие пассажиры: ");
  97.                 foreach (var x in gpass)
  98.                 {
  99.                     x.show(fileout);
  100.                 }
  101.             }
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement