Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 5. Top Integers
- 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.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _05TopIntegers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
- string result = "";
- for (int i = 0; i < array.Length; i++)
- {
- int current = array[i];
- bool isTopInteger = true;
- for (int a = i + 1; a < array.Length; a++)
- {
- if (current <= array[a])
- {
- isTopInteger = false;
- break;
- }
- }
- if (isTopInteger)
- {
- result += current + " ";
- }
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment