JulianJulianov

05. Top Integers

Feb 6th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. 5. Top Integers
  2. Write a program to find all the top integers in an array. A top integer is an integer which is bigger than all the elements to its right.
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace _05TopIntegers
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
  17.  
  18. string result = "";
  19. for (int i = 0; i < array.Length; i++)
  20. {
  21. int current = array[i];
  22. bool isTopInteger = true;
  23. for (int a = i + 1; a < array.Length; a++)
  24. {
  25. if (current <= array[a])
  26. {
  27. isTopInteger = false;
  28. break;
  29. }
  30. }
  31. if (isTopInteger)
  32. {
  33. result += current + " ";
  34. }
  35. }
  36. Console.WriteLine(result);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment