#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define Getsign(n) ((n > 0) - (n < 0)) typedef vector Ivec; typedef pair Pos; const pair dira[4] = { {0,1},{1,0},{0,-1},{-1,0} }; int main() { int n; int m[32][32] = {}; scanf("%d", &n); for (int i = 0; n + 1 > i; i++) { m[i][0] = -1; m[0][i] = -1; m[n + 1][i] = -1; m[i][n + 1] = -1; } Pos pos = { 1 ,1}; int cou = 1; int dir = 0; while (1) { if (m[pos.first][pos.second] != 0) { pos.first -= dira[dir].first; pos.second -= dira[dir].second; dir = (dir + 1) % 4; pos.first += dira[dir].first; pos.second += dira[dir].second; if (m[pos.first][pos.second]!= 0) { break; } continue; } m[pos.first][pos.second] = cou; pos.first += dira[dir].first; pos.second += dira[dir].second; cou++; } for (int i = 1; n + 1 > i; i++) { for (int j = 1; n + 1 > j; j++) { printf("%03d", m[i][j]); if (j != n)printf(" "); } printf("\n"); } return 0; }