-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircular_Array_Rotation.cpp
More file actions
50 lines (44 loc) · 963 Bytes
/
Circular_Array_Rotation.cpp
File metadata and controls
50 lines (44 loc) · 963 Bytes
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
/**
* Title : Circular_Array_Rotation.cpp
* Author : Tridib Samanta
* Created : 23-02-2020
* Link : https://www.hackerrank.com/challenges/circular-array-rotation/problem
**/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n,k,q,m;
scanf("%d%d%d",&n,&k,&q);
k=k%n;
int arr[n];
for(int i=k;i<n;i++)
scanf("%d",&arr[i]);
for(int i=0;i<k;i++)
scanf("%d",&arr[i]);
while(q--) {
scanf("%d",&m);
printf("%d\n",arr[m]);
}
return 0;
}
/*
ALTERNATIVE SOLUTION
k=k%n;
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
for(int i = 0; i < q; i++){
scanf("%d",&m);
if(m-k >= 0)
printf("%d\n",ar[m-k]);
else
printf("%d\n",ar[m-k+n]);
}
*/