Advertisement
loleckek228

3.5

Sep 10th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _3._5
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] intArray = new int[30];
  10.             int[] intMaxs = new int[0];
  11.            
  12.  
  13.             Random random = new Random();
  14.  
  15.             for (int i = 0; i < intArray.Length; i++)
  16.             {
  17.                 intArray[i] = random.Next(1, 10);
  18.             }
  19.  
  20.             for (int i = 0; i < intArray.Length; i++)
  21.             {
  22.                 Console.Write(intArray[i] + " ");
  23.             }
  24.  
  25.             if (intArray[0] > intArray[1])
  26.             {
  27.                 int[] newMaxsArray = new int[intMaxs.Length + 1];
  28.                 for (int i = 0; i < intMaxs.Length; i++)
  29.                 {
  30.                     newMaxsArray[i] = intMaxs[i];
  31.                 }
  32.                 newMaxsArray[intMaxs.Length] = intArray[0];
  33.                 intMaxs = newMaxsArray;
  34.             }      
  35.            
  36.             for (int j = 1; j < intArray.Length - 1; j++)
  37.             {
  38.                
  39.                 if (intArray[j] > intArray[j - 1] && intArray[j] > intArray[j + 1])                    
  40.                 {
  41.                     int[] newMaxsArray = new int[intMaxs.Length + 1];
  42.                     for (int i = 0; i < intMaxs.Length; i++)
  43.                     {
  44.                         newMaxsArray[i] = intMaxs[i];
  45.                     }
  46.                     newMaxsArray[intMaxs.Length] = intArray[j];
  47.                     intMaxs = newMaxsArray;                
  48.                 }              
  49.             }
  50.  
  51.             if (intArray[29] > intArray[28])
  52.             {
  53.                 int[] newMaxsArray = new int[intMaxs.Length + 1];
  54.                 for (int i = 0; i < intMaxs.Length; i++)
  55.                 {
  56.                     newMaxsArray[i] = intMaxs[i];
  57.                 }
  58.                 newMaxsArray[intMaxs.Length] = intArray[29];
  59.                 intMaxs = newMaxsArray;
  60.             }
  61.  
  62.             Console.WriteLine();
  63.             for (int i = 0; i < intMaxs.Length; i++)
  64.             {
  65.                 Console.Write(intMaxs[i] + " ");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement