Advertisement
vaibhav1906

Rotate Array (Abhishek)

Mar 20th, 2022
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.     //code
  6.     int t;
  7.     cin>>t;
  8.    
  9.     while(t--){
  10.        
  11.         vector<int> v;
  12.         int n, d;
  13.         cin>>n>>d;
  14.        
  15.         for(int i = 0; i<n; i++){
  16.             int x;
  17.             cin>>x;
  18.             v.push_back(x);
  19.         }
  20.        
  21.         vector<int> nv;
  22.        
  23.         int y = d;
  24.          
  25.         while(y<n){
  26.             nv.push_back(v[y]);
  27.             y++;
  28.         }
  29.         for(int i = 0; i<d; i++){
  30.             nv.push_back(v[i]);
  31.         }
  32.        
  33.         for(int i : nv){
  34.             cout<<i<<" ";
  35.         }
  36.         cout<<endl;
  37.        
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement