大佬求解,为啥会输出不了结果
查看原帖
大佬求解,为啥会输出不了结果
606717
cywscs楼主2021/11/20 13:27
#include<iostream>
using namespace std;
int main() {
	int n = 0, cnt = 1, x = 1, y = 0;
	int arr[15][15];
	cin >> n;
	while (cnt <= n * n)
	{
		for (; y < n && !arr[x][y + 1]; cnt++)
			arr[x][++y] = cnt;
		for (; x < n && !arr[x + 1][y]; cnt++)
			arr[x++][y] = cnt;
		for (; y > 1 && !arr[x][y - 1]; cnt++)
			arr[x][--y] = cnt;
		for (; x > 1 && !arr[x - 1][y]; cnt++)
			arr[--x][y] = cnt;

	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			cout << arr[i][j] << " ";
		}
		cout << endl;
	}


}

输入之后按回车没反应

参照了题解的解法用for写的

2021/11/20 13:27
加载中...