Advertisement
radostina92

Задача1Масив

May 12th, 2022
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. // само масив 1ва задача
  2. string[] inputArray = Console.ReadLine().Split(" ");
  3.  
  4. int[] arr = new int[inputArray.Length];
  5. for (int i = 0; i < arr.Length; i++)
  6. {
  7.     arr[i] = int.Parse(inputArray[i]);
  8. }
  9.  
  10.  
  11.  
  12. int[] result = new int[arr.Length];
  13.  
  14. for (int i = 0; i < arr.Length; i++)
  15. {
  16.  
  17.     if(i == 0)
  18.     {
  19.         continue;
  20.     }
  21.     else
  22.     {
  23.        if(arr[i - 1] < arr[i])
  24.         {
  25.             result[i] = arr[i];
  26.             result[i - 1] = 0;
  27.         }
  28.     }
  29.  
  30. }
  31.  
  32.     string a = "";
  33.  
  34. for (int i = 0; i < result.Length; i++)
  35. {
  36.     if (result[i] != 0)
  37.     {
  38.         a += result[i] + " ";
  39.     }
  40. }
  41.  
  42.  
  43.  
  44. Console.WriteLine(string.Join(" ", a));
  45. Console.WriteLine(a.Count() / 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement