Advertisement
Guest User

Array_Rotation

a guest
Jul 26th, 2019
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace Array_Rotation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] numArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
  10.  
  11.             int numRotations = int.Parse(Console.ReadLine());
  12.             int counterOne = numRotations - 1;
  13.             int counterTwo = numArray.Length - 1;
  14.             int[] switchedArray = new int[numArray.Length];
  15.  
  16.  
  17.  
  18.             for (int i = numArray.Length - 1; i >= 0; i--)
  19.             {
  20.  
  21.                 if (counterOne >= 0)
  22.                 {
  23.  
  24.                     switchedArray[i] = numArray[counterOne];
  25.                     counterOne--;
  26.                 }
  27.                 else
  28.                 {
  29.                     switchedArray[i] = numArray[counterTwo];
  30.                     counterTwo--;
  31.                 }
  32.  
  33.             }
  34.  
  35.             Console.WriteLine(String.Join(" ", switchedArray));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement