Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* --std=c++11 */
- #include <iostream>
- #include <iomanip>
- #include <cstdint>
- #include <random>
- //The solution
- void rotate90clockwise(uint32_t* image, int size)
- {
- for (int cycle = 0; cycle < size/2; cycle++)
- {
- int lastcol = size - cycle - 1;
- for (int col = cycle; col < lastcol; col++)
- {
- uint32_t tmp = image[cycle*size + col];
- image[cycle*size + col] = image[(size - col - 1)*size + cycle];
- image[(size - col - 1)*size + cycle] = image[lastcol*size + (size - col - 1)];
- image[lastcol*size + (size - col - 1)] = image[col*size + lastcol];
- image[col*size + lastcol] = tmp;
- }
- }
- }
- //To debug
- void fillrand(uint32_t* image, int size)
- {
- std::seed_seq seed = {1,2,323};
- seed.generate(image, image+size*size);
- }
- void printimage(uint32_t* image, int size)
- {
- for (int i = 0; i < size; i++)
- {
- for (int j = 0; j < size; j++)
- {
- std::cout << std::setw(10) << std::hex << image[i*size+j];
- }
- std::cout << std::endl;
- }
- }
- int main()
- {
- int N = 3;
- uint32_t* testimg = new uint32_t[N*N];
- fillrand(testimg, N);
- printimage(testimg, N);
- std::cout << "Rotate: \n";
- rotate90clockwise(testimg, N);
- printimage(testimg, N);
- delete[] testimg;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement