#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
vector<vector<int> > SpiralMatrix(int m)
{
vector<vector<int> > r(m, vector<int>(m,0));
int k = 0;
int n = m-1;
for(int layer = 0; layer <= n/2; ++layer)
{
for (int j = layer; j <= n-layer; ++j)
r[layer][j] = ++k;
for (int i = layer+1; i <= n-layer; ++i)
r[i][n-layer] = ++k;
for (int j = n-layer-1; j >= layer; --j)
r[n-layer][j] = ++k;
for (int i = n-layer-1; i >= layer+1; --i)
r[i][layer] = ++k;
}
return r;
}
void PrintVV(vector<vector<int> >& v)
{
for (int i = 0; i < v.size(); ++i)
{
for (int j = 0; j < v[i].size(); ++j)
{
cout<< setw(4) << v[i][j] << ',';
}
cout << '\n';
}
cout << endl;
}
int main(int argc, char** argv)
{
vector<vector<int> > v;
PrintVV(v=SpiralMatrix(1));
PrintVV(v=SpiralMatrix(3));
PrintVV(v=SpiralMatrix(4));
PrintVV(v=SpiralMatrix(7));
return 0;
}