60分求调
查看原帖
60分求调
766148
yzx_yzx楼主2024/7/11 11:23
#include <bits/stdc++.h>
using namespace std;
long long n, a[25][25];
bool aa[25][25];

int main() {
	cin >> n;
	int sygh = 1;
	int sygl = n / 2 + 1, ssgh = 1, ssgl = n / 2 + 1;
	a[sygh][sygl] = 1;
	aa[sygh][sygl] = 1;
	for (int i = 2; i <= n * n; i++) {
		sygh--;
		if (sygh < 1) {
			sygh = n;
		}
		sygl++;
		if (sygl > n) {
			sygl = 1;
		}
		if (aa[sygh][sygl] == 0) {
			a[sygh][sygl] = i;
			aa[sygh][sygl] = 1;
			ssgh = sygh + 1;
			if (ssgh > n) {
				ssgh = 1;
			}
			ssgl = sygl;
		} else if (aa[sygh][sygl] == 1) {
			a[ssgh][ssgl] = i;
			aa[ssgh ][ssgl] = 1;
			sygh = ssgh;
			sygl = ssgl;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}
	return 0;
}
2024/7/11 11:23
加载中...