nikolayneykov

Untitled

Feb 24th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         //[1, 2, 3, 4, 5] -> exchange 2 -> result: [4, 5, 1, 2, 3]
  8.         int[] arr = { 1, 2, 3, 4, 5 };
  9.         int[] exchanged = new int[arr.Length];
  10.         int index = 2;
  11.  
  12.         int originalIndex = 0;
  13.         int exchangedIndex = index;
  14.  
  15.         while (originalIndex < arr.Length)
  16.         {
  17.             exchanged[exchangedIndex] = arr[originalIndex];
  18.  
  19.            
  20.             if (exchangedIndex == arr.Length - 1)
  21.             {
  22.                 originalIndex = index;
  23.                 exchangedIndex = -1;
  24.             }
  25.             originalIndex++;
  26.             exchangedIndex++;
  27.         }
  28.  
  29.  
  30.         Console.WriteLine(string.Join(' ', exchanged));
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment