Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- namespace pr15.I._3
- {
- class Program
- {
- static void Main(string[] args)
- {
- // считываение данных
- string input;
- using (StreamReader filein = new StreamReader("C:/Users/belousaa/Documents/in1.txt"))
- {
- input = filein.ReadToEnd();
- }
- //приведение к целочисленному массиву
- char[] del = new char[] { ' ', '\n' };
- string[] numS = input.Split(del, StringSplitOptions.RemoveEmptyEntries);
- int[] numI = new int[numS.Length];
- for (int i = 0; i < numS.Length; i++)
- {
- numI[i] = int.Parse(numS[i]);
- }
- // считывание отрезка с клавиатуры
- //1 способ
- // описание запроса
- var sortedNum1 =
- from n in numI
- where (n > 0) && (n%2==0)
- orderby n
- select n;
- // вывод
- using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output1.txt", false))
- {
- foreach (var x in sortedNum1)
- {
- fileout.Write("{0} ", x);
- }
- }
- //2 способ
- // описание запроса
- var sortedNum2 = numI.Where(n => (n >0) && (n % 2 == 0)).OrderBy(n => n);
- // вывод
- using (StreamWriter fileout = new StreamWriter("C:/Users/belousaa/Documents/output2.txt", false))
- {
- foreach (var x in sortedNum2)
- {
- fileout.Write("{0} ", x);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement