Untitled
raw download clone
CPP
views 15
,
size 1020 b
#include <iostream>
using namespace std;

int main()
{
    int i, j, v[101][101] = {0}, n, s = 0, nmax=0;
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
        {
            if(i + j <= n + 1)
            {
                v[i][j]= min(i,j);
                if(v[i][j] > nmax)
                    nmax=v[i][j];
                int k=0;
                for(int q = 1; q<=v[i][j]; q++)
                    k = k + q;
                s = s + k;
            }
            else
            {
                v[i][j] = min(n-i+1,n-j+1);
                if(v[i][j] > nmax)
                    nmax = v[i][j];
                int k = 0;
                for(int q = 1; q<=v[i][j]; q++)
                    k = k + q;
                s = s + k;
            }
        }
    }
    cout << nmax << endl;
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= n; j++)
            cout << v[i][j];
        cout << endl;
    }
    cout << s;
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.