10 条题解

  • 1
    @ 2026-1-26 19:17:20
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	int n,k = 1;
    	cin >> n;
    	int a[101][101];
    	for(int i = 1;i <= (n + 1) / 2;i++)
    	{
    		for(int j = i;j <= n + 1 - i;j++)
    			a[i][j] = k++;
    		for(int j = i + 1;j <= n + 1 - i;j++)
    			a[j][n + 1 - i] = k++;
    		for(int j = n - i;j >= i;j--)
    			a[n + 1 - i][j] = k++;
    		for(int j = n - i;j >= i + 1;j--)
    			a[j][i] = k++;
    	}
    	for (int i = 1;i <= n;i++)
    	{
    		for (int j = 1;j <= n - 1;j++)
    			cout << a[i][j] << ' ';
    		cout << a[i][n];
    		if (i != n)
    			cout << endl; 
    	}
    	return 0;
    }
    //最短代码

    信息

    ID
    1043
    时间
    1000ms
    内存
    32MiB
    难度
    6
    标签
    递交数
    1004
    已通过
    310
    上传者