#include <iostream>
#include <vector>
using namespace std;
const int N = 100;
int main()
{
vector<vector<int>> w(N, vector<int>(N, 0));
int x = N / 2, y = N / 2;
int dx = 0, dy = -1;
for (int i = 0; i < N * N; i++)
{
w[x][y] = 1;
int nx = x + dy, ny = y - dx;
if (nx >= 0 && ny >= 0 && nx < N && ny < N && w[nx][ny] == 0)
{
int r = dx;
dx = -dy;
dy = r;
}
x += dx;
y += dy;
if (x < 0 || y < 0 || x >= N || y >= N || w[x][y] == 1)
{
x -= dx;
y -= dy;
int r = dx;
dx = -dy;
dy = r;
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cout << w[i][j];
}
cout << endl;
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <vector> using namespace std; const int N = 100; int main() { vector<vector<int>> w(N, vector<int>(N, 0)); int x = N / 2, y = N / 2; int dx = 0, dy = -1; for (int i = 0; i < N * N; i++) { w[x][y] = 1; int nx = x + dy, ny = y - dx; if (nx >= 0 && ny >= 0 && nx < N && ny < N && w[nx][ny] == 0) { int r = dx; dx = -dy; dy = r; } x += dx; y += dy; if (x < 0 || y < 0 || x >= N || y >= N || w[x][y] == 1) { x -= dx; y -= dy; int r = dx; dx = -dy; dy = r; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << w[i][j]; } cout << endl; } return 0; } |
English