fork download
  1. #include <stdio.h>
  2. #include <vector>
  3.  
  4. int value[1234][1234],value2[1234][1234];
  5. void rotate(int x0, int y0, int w, int h)
  6. {
  7. // (x0,y0) ~ (x0,y0+h)
  8. // (x0,y0+h) ~ (x0+w,y0+h)
  9. // (x0+w,y0+h) ~ (x0+w,y0)
  10. // (x0+w,y0) ~ (x0,y0)
  11.  
  12. std::vector< std::pair<int,int> > temp;
  13. for(int i=0;i<h;i++) temp.push_back(std::make_pair(x0,y0+i));
  14. for(int i=0;i<w;i++) temp.push_back(std::make_pair(x0+i,y0+h));
  15. for(int i=0;i<h;i++) temp.push_back(std::make_pair(x0+w,y0+h-i));
  16. for(int i=0;i<w;i++) temp.push_back(std::make_pair(x0+w-i,y0));
  17.  
  18. //rotate
  19. for(int i=0;i<temp.size();i++) value2[temp[(i+1)%temp.size()].first][temp[(i+1)%temp.size()].second] = value[temp[i].first][temp[i].second];
  20. for(int i=0;i<temp.size();i++) value[temp[i].first][temp[i].second] = value2[temp[i].first][temp[i].second];
  21. }
  22.  
  23. int main()
  24. {
  25. rotate(1,2,3,4);
  26. }
Success #stdin #stdout 0.01s 5372KB
stdin
Standard input is empty
stdout
Standard output is empty