fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. using namespace std;
  5.  
  6. int main() {
  7. int a[] = {22,33,44,55,66,77,88,99};
  8. auto k = 3;
  9. auto size = sizeof(a) / sizeof(a[0]);
  10.  
  11. rotate(begin(a), next(begin(a), ((-k % size) + size) % size), end(a));
  12.  
  13. for(auto& i : a) {
  14. cout << i << endl;
  15. }
  16. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
77
88
99
22
33
44
55
66