AC

⛆李恒旭₰₡₪∑¼☢Ⱉฅ☺☣☯☠  •  10个月前


单个数字要两个空格, 注意咯~ 下面是我的代码 请看:

include <bits/stdc++.h>

using namespace std; int a[105][105];

int main(void) {

int n, num = 1;
cin >> n;
int c = n, r = 1;
a[r][c] = num++;
while (num <= n * n) {
	while (!a[r + 1][c] && r < n)
		r++, a[r][c] = num++;
	while (!a[r][c - 1] && c > 1)
		c--, a[r][c] = num++;
	while (!a[r - 1][c] && r > 1)
		r--, a[r][c] = num++;
	while (!a[r][c + 1] && c < n)
		c++, a[r][c] = num++;
}
for (int i = 1; i <= n; i++) {
	for (int j = 1; j <= n; j++) {
		printf("%2d ", a[i][j]);
	}
	cout << endl;
}
return 0;

}


评论:

请先登录,才能进行评论