Skip to content

Instantly share code, notes, and snippets.

@nichtemna
Created September 22, 2016 13:40
Show Gist options
  • Save nichtemna/84b4bec09e7a68839597c8a7482c62b2 to your computer and use it in GitHub Desktop.
Save nichtemna/84b4bec09e7a68839597c8a7482c62b2 to your computer and use it in GitHub Desktop.
CircularRotation of array
public class CircularRotation {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int q = scanner.nextInt();
int[] array = new int[n];
for (int i = 0; i < array.length; i++) {
array[(i + k) % array.length] = scanner.nextInt();
}
for (int i = 0; i < q; i++) {
System.out.println(array[scanner.nextInt()]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment