Created
September 17, 2022 08:17
-
-
Save harsh-2024/419528a5cc0296cca30735ca01f00997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
void rev(int A[],int s, int e) | |
{ | |
int i = s; | |
int j = e; | |
while(1) | |
{ | |
if(i == j) | |
{ | |
break; | |
} | |
else if(j == i+1) | |
{ | |
swap(A[i],A[j]); | |
break; | |
} | |
else | |
{ | |
swap(A[i],A[j]); | |
i+=1; | |
j-=1; | |
} | |
} | |
} | |
int main() { | |
int N,D; | |
cin>>N>>D; | |
int A[N]; | |
for(int i=0;i<N;i++) | |
{ | |
cin>>A[i]; | |
} | |
if(D>N) | |
{ | |
D = D-N; | |
} | |
if(N !=D) | |
{ | |
rev(A,0,D-1); | |
rev(A,D,N-1); | |
rev(A,0,N-1); | |
} | |
for(int i=0;i<N;i++) | |
{ | |
cout<<A[i]<<" "; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment