skipter icon

C# Remove Negatives and Reverse List

skipter | PRO | 06/23/17 08:48:27 PM UTC | 0 ⭐ | 280 👁️ | Never ⏰ | []
C# |

900 B

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _1.RemoveNegativeRever
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> removeNegatives = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            bool IsEmpty = false;
            for (int cnt = 0; cnt < removeNegatives.Count; cnt++)
            {
                if (removeNegatives[cnt] < 0)
                {
                    removeNegatives.RemoveAt(cnt);
                    cnt--;
                }
            }
            removeNegatives.Reverse();
            if (removeNegatives.Count > 0)
            {
                Console.WriteLine(String.Join(" ", removeNegatives));
            } else
            {
                Console.WriteLine("empty");
            }
        }
    }
}

Comments