kilolilo

Untitled

Nov 3rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. void reverse_(int a[],int n){
  4.      for(int i=0;i<n/2;i++){
  5.          int b=a[i];
  6.          a[i]=a[n-i-1];
  7.          a[n-i-1]=b;
  8.      }
  9. }
  10.  
  11. void print(int a[], int n){
  12.     for(int j=0;j<n;j++){
  13.         cout<<a[j] << " ";
  14.     }
  15.     cout << endl;
  16. }
  17.  
  18. void run(int a[],int n,int s){
  19.     int shifted[s], remains[n-s];
  20.     for(int i=0;i<s;i++){
  21.         shifted[i] = a[n-s+i];
  22.     }
  23.     for (int i = 0; i < n - s; i++){
  24.         remains[i] = a[i];
  25.     }
  26.     for(int i=0;i<s;i++){
  27.         a[i]=shifted[i];
  28.     }
  29.     for(int i=0;i<n-s;i++){
  30.         a[s+i]=remains[i];
  31.     }
  32.  
  33. }
  34.  
  35. int main()
  36. {
  37.    int n=5,a[n]={1,2,3,4,5},s;
  38.    cin>>s;
  39.    for(int j=0;j<n;j++){
  40.        cout<<a[j] << " ";
  41.    }
  42.    cout << endl;
  43.    run(a,n,s);
  44.    for(int j=0;j<n;j++){
  45.        cout<<a[j] << " ";
  46.    }
  47.    cout << endl;
  48. }
Add Comment
Please, Sign In to add comment