gospod1978

List\Remove Negatives and Reverse

Oct 18th, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental14
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.          List<int> number = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.          for (int i = 0; i < number.Count; i++)
  13.             {
  14.                if (number[i] < 0)
  15.                {
  16.                   number.RemoveAt(i);
  17.                   i -= 1;
  18.                }
  19.             }
  20.            
  21.             number.Reverse();
  22.            
  23.            if (number.Count == 0)
  24.                {
  25.                  Console.WriteLine("empty");
  26.                }
  27.            else
  28.                {
  29.                  Console.WriteLine(string.Join(" ", number));
  30.                }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment