Advertisement
desislava_topuzakova

3. Изтриване на отрицателни елементи

Mar 18th, 2023
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Remove_Negatives
  6. {
  7. internal class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine().Split(" ").Select(int.Parse).ToList();
  12.  
  13. //1. премахваме отрицателните числ в списъка
  14. numbers.RemoveAll(number => number < 0);
  15.  
  16. //2. обръщаме списъка на обратно
  17. numbers.Reverse();
  18.  
  19. if (numbers.Count == 0)
  20. {
  21. Console.WriteLine("empty");
  22. }
  23. else
  24. {
  25. Console.WriteLine(String.Join(" ", numbers));
  26. }
  27. }
  28. }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement