7 solutions

  • -1
    @ 2024-12-6 13:29:11
    #include<bits/stdc++.h>
    using namespace std;
    const int N=20;
    int g[20][20];
    int main()
    {
    	int n;
    	cin>>n;
    	int cnt=1;
    	for(int i=1;i<=n;i++) //填写第i列的起点 
    	{
    		for(int x=1,y=i;x<=i;x++,y--) //从(1,i) 
    		{
    			g[x][y]=cnt++;
    		}
    	}
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n-i+1;j++)
    		{
                if(g[i][j] !=0)
    				cout<<g[i][j]<<" ";
    		}
    		cout<<endl;
    	}
    	return 0;
    }
    
    

    Information

    ID
    82
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    (None)
    # Submissions
    81
    Accepted
    29
    Uploaded By