fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. #define c(i,j) )std::cout<<m[i][j]<<" ";
  5. using M=std::vector<std::vector<int>>;void s(M&m,int h){int i,n=m.size(),k=n-h-1;if(n>2*h){for(i=h;i<=k;c(h,i++)for(i=h+1;i<=k;c(i++,k)for(i=k-1;i>=h;c(k,i--)for(i=k-1;i>h;c(i--,h)s(m,h+1);}}
  6.  
  7. M x{{1, 2, 3, 4}, {12, 13, 14, 5}, {11, 16, 15, 6}, {10, 9, 8, 7}};
  8. M y{{1, 2, 3}, {8, 9, 4}, {7, 6, 5}};
  9.  
  10. int main()
  11. {
  12. s(x,0);
  13. std::cout << "\n";
  14. s(y,0);
  15. std::cout << "\n";
  16. }
  17.  
  18.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
1 2 3 4 5 6 7 8 9