Teo_Yanchev

Lists - RemoveNegativesAndReverse - C# Fundamentals

Sep 13th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _5.RemoveNegativesAndReverse
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<int> postiveNumbers = new List<int>();
  17. bool isEmpty = false;
  18.  
  19. for (int i = numbers.Count - 1; i >= 0; i--)
  20. {
  21. if (numbers[i] >= 0)
  22. {
  23. postiveNumbers.Add(numbers[i]);
  24. isEmpty = true;
  25. }
  26. }
  27.  
  28. if (isEmpty)
  29. {
  30. Console.WriteLine(string.Join(" ", postiveNumbers));
  31. }
  32.  
  33. else
  34. {
  35. Console.WriteLine("empty");
  36. }
  37. }
  38. }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment