Advertisement
Ochkasty_Dino

Practicum15-I-5

Dec 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace pr15.I._3
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             // считываение данных
  12.             string input;
  13.             using (StreamReader filein = new StreamReader("C:/Users/belousaa/Documents/in1.txt"))
  14.             {
  15.                 input = filein.ReadToEnd();
  16.             }
  17.  
  18.             //приведение к целочисленному массиву
  19.             char[] del = new char[] { ' ', '\n' };
  20.             string[] numS = input.Split(del, StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.             int[] numI = new int[numS.Length];
  23.             for (int i = 0; i < numS.Length; i++)
  24.             {
  25.                 numI[i] = int.Parse(numS[i]);
  26.             }
  27.  
  28.             // считывание отрезка с клавиатуры
  29.            
  30.  
  31.  
  32.             //1 способ
  33.             // описание запроса
  34.             var sortedNum1 =
  35.                 from n in numI
  36.                 where (n > 0) && (n%2==0)
  37.                 orderby n
  38.                 select n;
  39.  
  40.             // вывод
  41.             using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output1.txt", false))
  42.             {
  43.                 foreach (var x in sortedNum1)
  44.                 {
  45.                     fileout.Write("{0} ", x);
  46.                 }
  47.             }
  48.  
  49.  
  50.             //2 способ
  51.             // описание запроса
  52.             var sortedNum2 = numI.Where(n => (n >0) && (n % 2 == 0)).OrderBy(n => n);
  53.  
  54.             // вывод
  55.             using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output2.txt", false))
  56.             {
  57.                 foreach (var x in sortedNum2)
  58.                 {
  59.                     fileout.Write("{0} ", x);
  60.                 }
  61.             }
  62.         }
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement