SHARE
TWEET

C#_Lists_1.5._Remove_Negatives_and_Reverse_V2

StoimenK Feb 28th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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._5._Remove_Negatives_and_Reverse_V2
  8. {
  9.     class Program
  10.     {
  11.         static void Main()              // Without lambda function // Lambda functionality is exchnaged with for Loop
  12.         {
  13.             List<int> inputNum = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.  
  15.             for (int i = 0; i < inputNum.Count; i++)
  16.             {
  17.                 if (inputNum[i] < 0)
  18.                 {
  19.                     inputNum.RemoveAt(i--);
  20.                 }
  21.             }
  22.  
  23.             if (inputNum.Count == 0)
  24.             {
  25.                 Console.WriteLine("empty");
  26.             }
  27.             inputNum.Reverse();
  28.  
  29.             Console.WriteLine(string.Join(" ", inputNum));
  30.         }
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top