Advertisement
Guest User

l'solution

a guest
Apr 24th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. /* --std=c++11 */
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdint>
  5. #include <random>
  6.  
  7. //The solution
  8. void rotate90clockwise(uint32_t* image, int size)
  9. {
  10.     for (int cycle = 0; cycle < size/2; cycle++)
  11.     {
  12.         int lastcol = size - cycle - 1;
  13.         for (int col = cycle; col < lastcol; col++)
  14.         {
  15.             uint32_t tmp = image[cycle*size + col];
  16.             image[cycle*size + col] = image[(size - col - 1)*size + cycle];
  17.             image[(size - col - 1)*size + cycle] = image[lastcol*size + (size - col - 1)];
  18.             image[lastcol*size + (size - col - 1)] = image[col*size + lastcol];
  19.             image[col*size + lastcol] = tmp;
  20.         }
  21.     }
  22. }
  23.  
  24. //To debug
  25. void fillrand(uint32_t* image, int size)
  26. {
  27.     std::seed_seq seed = {1,2,323};
  28.     seed.generate(image, image+size*size);
  29. }
  30.  
  31. void printimage(uint32_t* image, int size)
  32. {
  33.     for (int i = 0; i < size; i++)
  34.     {
  35.         for (int j = 0; j < size; j++)
  36.         {
  37.             std::cout << std::setw(10) << std::hex << image[i*size+j];
  38.         }
  39.         std::cout << std::endl;
  40.     }
  41. }
  42.  
  43. int main()
  44. {
  45.     int N = 3;
  46.     uint32_t* testimg = new uint32_t[N*N];
  47.     fillrand(testimg, N);
  48.     printimage(testimg, N);
  49.     std::cout << "Rotate: \n";
  50.     rotate90clockwise(testimg, N);
  51.     printimage(testimg, N);
  52.     delete[] testimg;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement