Advertisement
Grimmjow1

04. Array Rotation

May 30th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ArrayRotation
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();  // 1 2 3 4
  11.             int rotations = int.Parse(Console.ReadLine());
  12.  
  13.             for (int i = 0; i < rotations; i++)
  14.             {
  15.                 int firstElemet = array[0];  // 1
  16.                 for (int j = 0; j < array.Length-1; j++)
  17.                 {
  18.                     array[j] = array[j + 1];  // 2 3 4 4
  19.                 }
  20.                 array[array.Length - 1] = firstElemet; // 2 3 4 1
  21.  
  22.             }
  23.             Console.WriteLine(string.Join(" ",array));
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement