74 solutions

  • -1
    @ 2025-7-2 9:13:50

    #include<bits/stdc++.h> using namespace std; const int N=20; int g[N][N]; int main() { int n; cin>>n; int cnt=1; for(int i=1;i<=n;i++) //填写第i列的起点 { if(i%2==0) //偶数行左上到右下 { for(int x=1,y=i;x<=i;x++,y--) //从(1,i) { g[x][y]=cnt++; } } else //奇数行左下到右上 { for(int x=i,y=1;y<=i;x--,y++) //从(i,1) { g[x][y]=cnt++; } }

    }
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=n-i+1;j++)
    	{
    		cout<<g[i][j]<<" ";
    	}
    	cout<<endl;
    }
    return 0;
    

    }

    Information

    ID
    838
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    2
    Tags
    # Submissions
    371
    Accepted
    104
    Uploaded By