koksibg

Remove_Negatives_and_Reverse

Oct 5th, 2016
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 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 Remove_Negatives_and_Reverse
  8. {
  9.     class Remove_Negatives_and_Reverse
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> list = Console.ReadLine()
  14.                 .Split()
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.             List<int> result = new List<int>();
  18.             foreach ( int num in list)
  19.             if (num >= 0) result.Add(num);
  20.             {
  21.                 result.Reverse();
  22.             }
  23.             if (result.Count > 0)
  24.             {
  25.                 Console.WriteLine(string.Join(" ", result));
  26.             }
  27.             else
  28.             {
  29.                 Console.WriteLine("empty");  
  30.             }
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment