Advertisement
STANAANDREY

permutari_circ

Jun 22nd, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int v[1000000],n,p,i,k,aux,x;
  4. int dir;
  5. int main()
  6. {
  7. cout<<"directie(1-dreapta;0-stanga):";cin>>dir;
  8. cout<<"n=";cin>>n;
  9. cout<<"k=";cin>>k;
  10. cout<<"sir"<<endl;
  11. for (i=0;i<n;i++)
  12. cin>>v[i];//*/
  13. if (k)
  14. k%=n;
  15. //spre drapta
  16. if (dir) {
  17. for (int j=0;j<k;j++)
  18. {
  19. x=v[n-1];
  20. for (i=n-2;i>=0;i--)
  21.     v[i+1]=v[i];
  22. v[0]=x;
  23. }
  24. cout<<"spre dreapta cu k:";
  25. for (i=0;i<n;i++)
  26. cout<<v[i]<<' ';}
  27. else{
  28. for (int j=0;j<k; j++)
  29. {
  30.     x=v[0];
  31. for (i=1;i<n;i++)
  32.     v[i-1]=v[i];
  33. v[n-1]=x;
  34. }
  35. cout<<"spre sanga cu k:";
  36. for (i=0;i<n;i++)
  37. cout<<v[i]<<' ';}
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement