Created
November 19, 2015 07:40
-
-
Save 30mb1/84ad5f6c460298374e98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
void rotate(std::vector<int> vect, int move, int n) { | |
int move1; | |
move = move % n; | |
std::vector<int> sortVec(n); | |
for (int ii = 0; ii < n; ii++) { | |
if (ii + move >= n) { | |
move1 = (ii + move) % n; | |
sortVec[move1] = vect[ii]; | |
} else if (ii + move < 0) { | |
move1 = n + (ii + move); | |
sortVec[move1] = vect[ii]; | |
} else { | |
move1 = ii + move; | |
sortVec[move1] = vect[ii]; | |
} | |
} | |
if (move == 0) { | |
for (auto i : vect) { | |
std::cout << i << " "; | |
} | |
} else { | |
for (auto i : sortVec) { | |
std::cout << i << " "; | |
} | |
} | |
} | |
int main() { | |
int n; | |
std::cin >> n; | |
if (n == 0) { | |
std::cout << ""; | |
} else { | |
std::vector<int> Vec; | |
for (int i = 0; i < n; i++) { | |
int figure; | |
std::cin >> figure; | |
Vec.push_back(figure); | |
} | |
int move; | |
std::cin >> move; | |
rotate(Vec, move, n); | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment