diff options
feat(Week07): Add solutions
1 files changed, 32 insertions, 0 deletions
| -rw-r--r-- | Week07/Exercise08.cpp | 32 |
diff --git a/Week07/Exercise08.cpp b/Week07/Exercise08.cpp new file mode 100644 index 0000000..375d1d4 --- /dev/null +++ b/Week07/Exercise08.cpp @@ -0,0 +1,32 @@ +#include <iostream> + +void rotate(const unsigned int* input, unsigned int size, unsigned int rotation, unsigned int* output) { + rotation %= size; + + for (unsigned int i = 0; i < size; i++) + output[(i + rotation) % size] = input[i]; +} + +// Никой не е забранил да правим допълнителни функции. +// ВНИМАНИЕ: входния размер ТРЯБВА да бъде константа! +void rotateUserInput(const unsigned int SIZE) { + unsigned int series[SIZE], rotation; + + for (unsigned int i = 0; i < SIZE; i++) + std::cin >> series[i]; + std::cin >> rotation; + + unsigned int result[SIZE]; + rotate(series, SIZE, rotation, result); + + for (unsigned int i = 0; i < SIZE; i++) + std::cout << result[i] << ' '; + std::cout << std::endl; +} + +int main() { + rotateUserInput(6); + rotateUserInput(7); + + return 0; +} |
