Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- void shift_mas (int mas[], int n, int k){
- int first_index, second_index, temp_first, temp_second;
- first_index = 0;
- temp_first = mas[first_index];
- for (int i = 0; i < n; i++){
- second_index = ( first_index + k ) % n;
- temp_second = mas[second_index];
- mas[second_index] = temp_first;
- temp_first = temp_second;
- first_index = second_index;
- }
- }
- void print_mas(int mas[], int n){
- ofstream out ("output.txt");
- for (int i = 0; i < n; i++){
- out << mas[i] << " ";
- }
- out.close();
- }
- int main () {
- ifstream in("input.txt");
- const int N_MAX = 100000;
- int n, k, mas[N_MAX];
- in >> n;
- for (int i = 0; i < n; i++) in >> mas[i];
- in >> k;
- if ( k >= 0 ) k %= n; else k = n - (-k) % n;
- shift_mas(mas, n, k);
- print_mas(mas, n);
- in.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement