Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Array_Rotation
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int rotationsInput = int.Parse(Console.ReadLine());
- // check if rotation is bigger than the array length to make a single rotation
- if(rotationsInput > arr.Length)
- {
- rotationsInput -= arr.Length;
- }
- // make a new array
- int[] newArr = new int[arr.Length];
- // count of numbers that are put from the old to the new array
- int numbersCount = 0;
- // fill the new array with the offset from the old
- for (int i = 0; i < arr.Length - rotationsInput; i++)
- {
- newArr[i] = arr[i + rotationsInput];
- numbersCount++;
- }
- // iterator for the old array
- int arrIt = 0;
- // fill the rest of the new array with the values skipped in the previous cycle
- for(int j = numbersCount; j < newArr.Length; j++)
- {
- newArr[j] = arr[arrIt];
- arrIt++;
- }
- // read the new array
- for (int i = 0; i < newArr.Length; i++)
- {
- Console.Write(newArr[i] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement