Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. import java.text.*;
  4. import java.math.*;
  5. import java.util.regex.*;
  6.  
  7. public class Solution {
  8.  
  9.     public static int[] arrayLeftRotation(int[] a, int n, int k) {
  10.         int move_count = k;
  11.             int[] b = new int[n];
  12.             while (move_count>n)
  13.                 move_count = move_count - n;
  14.             for(int cnt = 0; cnt<n; cnt ++){
  15.                 int check = cnt - move_count;
  16.                 if (check<0){
  17.                     int loc = n + check;
  18.                     b[loc] = a[cnt];
  19.                 }
  20.                 else
  21.                     b[check] = a[cnt];
  22.             }
  23.             return b;
  24.            
  25.      
  26.     }
  27.    
  28.     public static void main(String[] args) {
  29.         Scanner in = new Scanner(System.in);
  30.         int n = in.nextInt();
  31.         int k = in.nextInt();
  32.         int a[] = new int[n];
  33.         for(int a_i=0; a_i < n; a_i++){
  34.             a[a_i] = in.nextInt();
  35.         }
  36.      
  37.         int[] output = new int[n];
  38.         output = arrayLeftRotation(a, n, k);
  39.         for(int i = 0; i < n; i++)
  40.             System.out.print(output[i] + " ");
  41.      
  42.         System.out.println();
  43.        
  44.  
  45.      
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement