Advertisement
aspire12

05.TopIntegers

Feb 11th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05.TopIntegers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //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.
  10.  
  11.             string[] inputArray = Console.ReadLine().Split();
  12.             int[] topIntegersArray = new int[1];
  13.             for (int i = 0; i < inputArray.Length - 1; i++)
  14.             {
  15.                 if(int.Parse(inputArray[i]) > int.Parse(inputArray[i + 1]))
  16.                 {
  17.                     topIntegersArray[topIntegersArray.Length - 1] = int.Parse(inputArray[i]);
  18.                     int[] tempIntegerArray = topIntegersArray;
  19.                     topIntegersArray = new int[topIntegersArray.Length + 1];
  20.                     for (int k = 0; k < topIntegersArray.Length - 1; k++)
  21.                     {
  22.                         topIntegersArray[k] = tempIntegerArray[k];
  23.                     }
  24.                    
  25.                 }
  26.             }
  27.             topIntegersArray[topIntegersArray.Length - 1] = int.Parse(inputArray[inputArray.Length - 1]);
  28.             Console.WriteLine(string.Join(" ", topIntegersArray));
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement