Advertisement
radidim

04.Array Rotation (C# Shell App Paste)

Dec 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace CSharp_Shell
  8. {
  9.  
  10.     public static class Program
  11.     {
  12.         public static void Main()
  13.         {
  14.            int[] arr = Console.ReadLine()
  15.            .Split()
  16.            .Select(int.Parse)
  17.            .ToArray();
  18.            
  19.            int n = int.Parse(Console.ReadLine());
  20.            for (int i=0; i<n; i++)
  21.            {
  22.            
  23.            int[] rotated = new int[arr.Length];
  24.            
  25.            for(int j=0; j< arr.Length-1;j++)
  26.            {
  27.                
  28.                int a = arr[0];
  29.                
  30.                rotated[j] = arr[j+1];
  31.                
  32.                rotated[arr.Length-1] = a;
  33.                
  34.            }
  35.            arr = rotated;
  36.            
  37.                
  38.            }
  39.            
  40.            Console.WriteLine(string.Join(" ", arr));
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement