LusienGG

[C#][Lists]Remove Negative and Reverse

May 9th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ListsAndMatrices
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             List<int> possitiveNumbers = new List<int>();
  15.             OnlyPossitiveList(numbers,possitiveNumbers);
  16.             possitiveNumbers.Reverse();
  17.             PrintList(possitiveNumbers);
  18.         }
  19.         public static void OnlyPossitiveList(List<int> list,List<int> resultList)
  20.         {
  21.             foreach (var item in list)
  22.             {
  23.                 if (item>=0)
  24.                 {
  25.                     resultList.Add(item);
  26.                 }
  27.             }
  28.         }
  29.         public static void PrintList(List<int> list)
  30.         {
  31.             foreach (var item in list)
  32.             {
  33.                 Console.WriteLine(item);
  34.             }
  35.         }
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment