skipter

C# Remove Negatives and Reverse List

Jun 23rd, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 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 _1.RemoveNegativeRever
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> removeNegatives = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             bool IsEmpty = false;
  15.             for (int cnt = 0; cnt < removeNegatives.Count; cnt++)
  16.             {
  17.                 if (removeNegatives[cnt] < 0)
  18.                 {
  19.                     removeNegatives.RemoveAt(cnt);
  20.                     cnt--;
  21.                 }
  22.             }
  23.             removeNegatives.Reverse();
  24.             if (removeNegatives.Count > 0)
  25.             {
  26.                 Console.WriteLine(String.Join(" ", removeNegatives));
  27.             } else
  28.             {
  29.                 Console.WriteLine("empty");
  30.             }
  31.         }
  32.     }
  33. }
Add Comment
Please, Sign In to add comment