#include <vector>
#include <iostream>
using namespace std;
void RotateMatrix(vector<vector<int> > &matrix)
{
size_t m = matrix.size() -1;
if (m <= 0) return;
for (int i = 0; i <= m/2; ++i)
for (int j = i; j < m-i; ++j)
{
int tmp = matrix[i][j];
matrix[i][j] = matrix[m-j][i];
matrix[m-j][i] = matrix[m-i][m-j];
matrix[m-i][m-j] = matrix[j][m-i];
matrix[j][m-i] = tmp;
}
}
void RotateWithFlip(vector<vector<int> >& matrix)
{
int m = matrix.size()-1;
for (int i = 0; i <= m; ++i)
for (int j = 0; j < i; ++j)
{
int tmp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = tmp;
}
for (int i = 0; i <= m; ++i)
for (int j = 0; j < (m+1)/2; ++j)
{
int tmp = matrix[i][j];
matrix[i][j] = matrix[i][m-j];
matrix[i][m-j] = tmp;
}
}
void PrintVV(vector<vector<int> >& m)
{
for (size_t i = 0; i < m.size(); ++i)
{
vector<int>& v = m[i];
for (size_t j = 0; j < v.size(); ++j)
cout << v[j] <<",\t";
cout << '\n';
}
cout << '\n';
}
int main(int argc, char** argv)
{
int k = 0;
int n = 5;
vector<vector<int> > m;
for (int i = 0; i < n; ++i)
{
vector<int> v;
for (int j = 0; j < n; ++j)
v.push_back(++k);
m.push_back(v);
}
PrintVV(m);
RotateMatrix(m);
PrintVV(m);
return 0;
}