#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ int i, j; int n; vector>flag(55, vector(55, false)); vector>matrix(55, vector(55, 0)); int x = 0, y = 0, num = 1; cin >> n; if (n == 1) { cout << "001" << endl; return 0; } else if (n == 2) { cout << "001" << " " << "002" << endl; cout << "004" << " " << "003" << endl; return 0; } while (true) { bool flag2 = false; for (i = 0; i < n; i++) { if (flag[y][x] == true) { break; } else { matrix[y][x] = num; flag[y][x] = true; x++; num++; flag2 = true; } } x--; y++; for (i = 0; i < n - 1; i++) { if (flag[y][x] == true) { break; } else { matrix[y][x] = num; flag[y][x] = true; y++; num++; flag2 = true; } } y--; x--; for (i = 0; i < n - 1; i++) { if (flag[y][x] == true || x < 0) { break; } else { matrix[y][x] = num; flag[y][x] = true; x--; num++; flag2 = true; } } x++; y--; for (i = 0; i < n - 1; i++) { if (flag[y][x] == true) { break; } else { matrix[y][x] = num; flag[y][x] = true; y--; num++; flag2 = true; } } x++; y++; if (flag2 == false) { break; } /* for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cout << setw(3) << setfill('0') << matrix[i][j]; if (j != n - 1) { cout << " "; } } cout << endl; } cout << endl;*/ } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cout << setw(3) << setfill('0') << matrix[i][j]; if (j != n - 1) { cout << " "; } } cout << endl; } getchar(); getchar(); return 0; }