BubaLazi

Lists-Lab01RemoveNegAndReverse

Aug 4th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 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 MultiDictionaries
  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> result = new List<int>();
  15.  
  16.             for(int i = 0; i < numbers.Count; i++)
  17.             {
  18.                 if (numbers[i] > 0)
  19.                 {                    
  20.                     result.Add(numbers[i]);
  21.                 }
  22.             }
  23.  
  24.             result.Reverse();
  25.  
  26.             if (result.Count == 0)
  27.             {
  28.                 Console.WriteLine("empty");
  29.             }
  30.             else
  31.             {              
  32.                 Console.Write(string.Join(" ", result));
  33.                 Console.WriteLine();
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment