6 solutions

  • 0
    @ 2026-11-14 10:20:13
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int c=n,x;
        for(int i=1;i<=n;i++){
            x=i;
            for(int j=1;j<=n;j++){
                if(i==1){
                    cout<<j<<" ";
                }
                else{
                    if(i>1){
                        n=n-i+1;
                        while(i>1){
                            cout<<i<<" ";
                            i--;
                        }
                        cout<<j<<" ";
                    }
                }
            }
            cout<<endl;
            i=x;
            n=c;
        }
        return 0;
    }
    

    Information

    ID
    73
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    1
    Tags
    (None)
    # Submissions
    77
    Accepted
    56
    Uploaded By