Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 04. Array Rotation
- Write a program that receives an array and number of rotations you have to perform (first element goes at the end) Print the resulting array.
- Examples
- Input Output
- 51 47 32 61 21 32 61 21 51 47
- 2
- 32 21 61 1 32 21 61 1
- 4
- 2 4 15 31 4 15 31 2
- 5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04ArrayRotation
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] array = Console.ReadLine().Split();
- var counter = int.Parse(Console.ReadLine());
- for (int a = 0; a < counter; a++)
- {
- string temporary = array[0];//string temporary = array[array.Length - 1]
- for (int i = 0; i < array.Length - 1; i++)//for (int i = array.Length - 1; i > 0; i--)
- { // Така ще ги завърти като последния елемент става първи.
- array[i] = array[i + 1];//array[i] = array[i - 1];
- }
- array[array.Length - 1] = temporary;//array[0] = temporary;
- }
- Console.WriteLine(string.Join(" ", array));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment