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[] array = Console.ReadLine().Split().ToArray();
- int numRotations = int.Parse(Console.ReadLine());
- string[] rotatedArray = new string[array.Length];
- if (numRotations > array.Length)
- numRotations -= array.Length;
- for (int i = 0; i < array.Length; i++)
- {
- if (i < numRotations)
- rotatedArray[array.Length + i - numRotations] = array[i];
- else
- rotatedArray[i - numRotations] = array[i];
- }
- string rotatedResult = string.Join(' ', rotatedArray);
- Console.WriteLine(rotatedResult);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement