fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5. std::vector<int> v;
  6. int k = 0, len = 0, num = 0;
  7.  
  8. std::cin >> k >> len;
  9. for (int i = 0; i < len; i++)
  10. {
  11. std::cin >> num;
  12. v.push_back (num);
  13. }
  14.  
  15. for (i: v) std::cout << i << " ";
  16.  
  17. // reverse
  18. for (int i = 0; i < len; i++)
  19. {
  20. if ((v[i] + k - 1) % len != 0)
  21. v[i] = (v[i] + k - 1) % len;
  22. else
  23. v[i] = v[i] + k - 1;
  24. }
  25.  
  26. std::cout << std::endl;
  27. for (i: v) std::cout << i << " ";
  28. return 0;
  29. }
Success #stdin #stdout 0s 3464KB
stdin
3
5
1 2 3 4 5
stdout
1 2 3 4 5 
3 4 5 1 2