#include #include #include #include #include #include #include #include #include #include using namespace std; #ifdef _WIN32 #include #endif int main() { int n, x = 0, y = 0, num = 1, dir = 0; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; cin >> n; vector> v(n, vector(n, 0)); for (int i = 0; i < n*n; i++){ v[y][x] = i + 1; int tx = x + dx[dir%4], ty = y + dy[dir%4]; if ((tx >= n) || (ty >= n) || (tx < 0) || (ty < 0) || (v[ty][tx] != 0)) dir++; x += dx[dir%4]; y += dy[dir%4]; } for (int i = 0; i < n; i++){ for (int j = 0; j < n; j++){ printf("%03d", v[i][j]); cout << ((j != n-1) ? " " : "\n"); } } }