fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. printArray(f(new int[]{1,2,3,4,5,6,7,8},1));
  13. printArray(f(new int[]{1,2,3,4,5,6,7,8},2));
  14. printArray(f(new int[]{-23,-37,52,0,-6,-7,-8,89},7));
  15. printArray(f(new int[]{4,8,15,16,23,42},0));
  16. printArray(f(new int[]{10,11,8,15,13,13,19,3,7,3,15,19},11));
  17. printArray(f(new int[]{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, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100},23));
  18. }
  19.  
  20. static void printArray(int[]array){
  21. System.out.print("[");
  22. for(int x:array)System.out.print(x+" ");
  23. System.out.println("]");
  24. }
  25.  
  26. static int[]f(int[]a,int n){for(int x,q=a.length,d[];0<n--;a=d){d=new int[q];for(x=0;x<q;x++)d[(2*x+2*x/q)%q]=a[x];}return a;}
  27.  
  28. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
[1 5 2 6 3 7 4 8 ]
[1 3 5 7 2 4 6 8 ]
[-23 -6 -37 -7 52 -8 0 89 ]
[4 8 15 16 23 42 ]
[10 19 11 3 8 7 15 3 13 15 13 19 ]
[1 30 59 88 18 47 76 6 35 64 93 23 52 81 11 40 69 98 28 57 86 16 45 74 4 33 62 91 21 50 79 9 38 67 96 26 55 84 14 43 72 2 31 60 89 19 48 77 7 36 65 94 24 53 82 12 41 70 99 29 58 87 17 46 75 5 34 63 92 22 51 80 10 39 68 97 27 56 85 15 44 73 3 32 61 90 20 49 78 8 37 66 95 25 54 83 13 42 71 100 ]