Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _05.TopIntegers
- {
- class Program
- {
- static void Main(string[] args)
- {
- //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.
- string[] inputArray = Console.ReadLine().Split();
- int[] topIntegersArray = new int[1];
- for (int i = 0; i < inputArray.Length - 1; i++)
- {
- if(int.Parse(inputArray[i]) > int.Parse(inputArray[i + 1]))
- {
- topIntegersArray[topIntegersArray.Length - 1] = int.Parse(inputArray[i]);
- int[] tempIntegerArray = topIntegersArray;
- topIntegersArray = new int[topIntegersArray.Length + 1];
- for (int k = 0; k < topIntegersArray.Length - 1; k++)
- {
- topIntegersArray[k] = tempIntegerArray[k];
- }
- }
- }
- topIntegersArray[topIntegersArray.Length - 1] = int.Parse(inputArray[inputArray.Length - 1]);
- Console.WriteLine(string.Join(" ", topIntegersArray));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement