2 solutions

  • 0
    @ 2026-10-24 19:42:42
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int h=n/2+1;
        int x=1,y=h;
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(abs(x-i)+abs(y-j)==h-1)
                {
                    cout<<"+";
                }
                else
                {
                    cout<<"-";
                }
            }
            cout<<endl;
        }
        x=n;
        for(int i=h+1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(abs(x-i)+abs(y-j)==h-1)
                {
                    cout<<"+";
                }
                else
                {
                    cout<<"-";
                }
            }
            cout<<endl;
        }
    	return 0;
    }
    

    Information

    ID
    1177
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    (None)
    # Submissions
    84
    Accepted
    34
    Uploaded By