Advertisement
YavorGrancharov

Remove_Negatives_and_Reverse_[List]

Jun 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 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 Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> nums = Console.ReadLine()
  14.                 .Split(' ')
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.  
  18.             List<int> empty = new List<int>();
  19.  
  20.             foreach (int n in nums)
  21.             {
  22.                 if (n >= 0)
  23.                 {
  24.                     empty.Add(n);
  25.                 }
  26.             }
  27.  
  28.             foreach (int n in nums)
  29.             {
  30.                 if (n < 0)
  31.                 {
  32.                     empty.Remove(n);
  33.                 }
  34.             }
  35.  
  36.             empty.Reverse();
  37.  
  38.             if (!empty.Any())
  39.             {
  40.                 Console.WriteLine("empty");
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine(String.Join(" ", empty));
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement