-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circular Array Rotation.cs
75 lines (57 loc) · 1.77 KB
/
Circular Array Rotation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int[] RotarDerecha(int[] arr, int k)
{
k = k % arr.Length;
int[] rotado = new int[arr.Length];
int i = 0;
for (i = k; i < rotado.Length; i++)
{
rotado[i] = arr[i - k];
}
for (int j = i - k; j < arr.Length; j++)
{
rotado[j - (i - k)] = arr[j];
}
return rotado;
}
static void Main()
{
int[] arr = { 1, 2, 3, 4, 5 };
int[] rotado = RotarDerecha(arr, 6);
foreach (int elem in rotado)
{
Console.Write(elem + " ");
}
Console.ReadLine();
}
//static void Main(string[] args)
//{
// //int[] arr = { 1, 2, 3, 4, 5 };
// //int[] rotado = RotarDerecha(arr, 3);
// //foreach (int elem in rotado)
// //{
// // Console.Write(elem + " ");
// //}
// string[] tokens_n = Console.ReadLine().Split(' ');
// int n = Convert.ToInt32(tokens_n[0]);
// int k = Convert.ToInt32(tokens_n[1]);
// int q = Convert.ToInt32(tokens_n[2]);
// string[] a_temp = Console.ReadLine().Split(' ');
// int[] a = Array.ConvertAll(a_temp,e=> int.Parse(e));
// int[] rotado = RotarDerecha(a, k);
// for (int a0 = 0; a0 < q; a0++)
// {
// int m = Convert.ToInt32(Console.ReadLine());
// Console.WriteLine(rotado[m]);
// }
// Console.ReadLine();
//}
}
}