Skip to content

Instantly share code, notes, and snippets.

@jaideepheer
Last active April 1, 2019 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaideepheer/58a50b5dc0d4f77ca40f75696a067dfc to your computer and use it in GitHub Desktop.
Save jaideepheer/58a50b5dc0d4f77ca40f75696a067dfc to your computer and use it in GitHub Desktop.
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
/**
* IGNORE ALL COMMENTS ABOVE THIS
* THAT IS BULLSH*T...!
* (╯°□°)╯︵ ┻━┻
*/
int numberOfElements = 5;
int toRotate = -2; // -ve for left rot. +ve for right rot., or maybe vice-versa ¯\_(ツ)_/¯
/*
Mai input lena bhool gaya ヽ(。_°)ノ
Input lele idhar
(ʘ‿ʘ)
*/
// [ input numberOfElements here ]
int elements[] = new int[numberOfElements]; // make array after numberOfElements input
// [ input array elements here ]
// [ input remaining stuff ]
// Rotation logic
int start = 0; // 0th position is start initially.
start = (start + toRotate + numberOfElements)%numberOfElements; // rotate elements
// Print rotated array
int finalArray[] = new int[numberOfElements];
for(int i=0;i<numberOfElements;++i)
{
System.out.print(elements[(start+i)%numberOfElements]+", ");
finalArray[i] = elements[(start+i)%numberOfElements];
}
// cleanup
elements = null;
System.gc(); // lol, just kidding delete this :P
/**
* (\____/)
( ͡ ͡° ͜ ʖ ͡ ͡°) done..
\╭☞ \╭☞
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment