Advertisement
remote87

Remove Negatives and Reverse

Oct 19th, 2016
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 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 _10.RemoveNegativesAndReverse
  8. {
  9.     public class RemoveNegativesAndReverse
  10.     {
  11.         public static void Main(string[] args)
  12.         {
  13.             string inputStr = Console.ReadLine();
  14.             string[] inputArr = inputStr.Split(' ');
  15.             List<int> inputInt = new List<int>();
  16.             List<int> newIntList = new List<int>();
  17.             for (int i = 0; i < inputArr.Length; i++)
  18.             {
  19.                 inputInt.Add(int.Parse(inputArr[i]));
  20.             }
  21.  
  22.             for (int i = 0; i < inputInt.Count; i++)
  23.             {
  24.                 if (inputInt[i] > 0)
  25.                 {
  26.                     newIntList.Add(inputInt[i]);
  27.                 }
  28.             }
  29.  
  30.             if (newIntList.Any())
  31.             {
  32.                 newIntList.Reverse();
  33.                 foreach (var item in newIntList)
  34.                 {
  35.                     Console.WriteLine(item);
  36.                 }
  37.                
  38.             }
  39.             else
  40.             {
  41.                 Console.WriteLine("empty");
  42.             }
  43.            
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement