听灌多
  • 板块灌水区
  • 楼主abababwosb
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/7 17:17
  • 上次更新2024/10/7 19:50:34
查看原帖
听灌多
1276415
abababwosb楼主2024/10/7 17:17

B3940,很奇怪的错误

#include <bits/stdc++.h>
using namespace std;

int a[50][50];

int main() {
	int n, x, y, cnt = 2;
	cin >> n;
	x = 1;
	y = n / 2 + 1;
	a[x][y] = 1;
	for (int i = 1; i < n * n; ++i) {
		if (x == 1) {
			x = n;
		} else {
			x--;
		}
		if (y == n) {
			y = 1;
		} else {
			y++;
		}
		if (a[x][y] == 0) {
			a[x][y] = cnt;
			cnt++;
		} else {
			if (x == n) {
				x = 1;
			} else {
				x++;
			}
			a[x][y] = cnt;
			cnt++;
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}
2024/10/7 17:17
加载中...