Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int v[1000000],n,p,i,k,aux,x;
- int dir;
- int main()
- {
- cout<<"directie(1-dreapta;0-stanga):";cin>>dir;
- cout<<"n=";cin>>n;
- cout<<"k=";cin>>k;
- cout<<"sir"<<endl;
- for (i=0;i<n;i++)
- cin>>v[i];//*/
- if (k)
- k%=n;
- //spre drapta
- if (dir) {
- for (int j=0;j<k;j++)
- {
- x=v[n-1];
- for (i=n-2;i>=0;i--)
- v[i+1]=v[i];
- v[0]=x;
- }
- cout<<"spre dreapta cu k:";
- for (i=0;i<n;i++)
- cout<<v[i]<<' ';}
- else{
- for (int j=0;j<k; j++)
- {
- x=v[0];
- for (i=1;i<n;i++)
- v[i-1]=v[i];
- v[n-1]=x;
- }
- cout<<"spre sanga cu k:";
- for (i=0;i<n;i++)
- cout<<v[i]<<' ';}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement