Untitled
raw download clone
TEXT
views 40
,
size 809 b
#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[101];
    for(int i = 1 ; i <= n ; ++i)
    a[i]=1;
    int c=n;
    if(n%2==1)
    c++;
    int s=0;
    cout << c/2 << endl;
    for(int i = 1 ; i <= c/2 ; ++i)
    {
        for(int j = 1 ; j <= n ; ++j)
        {
            cout << a[j];    
        }
        cout << endl;
        for(int j = i+1 ; j <= n-i ; ++j)
        a[j]++;
    }
    for(int i = n/2 ; i >= 1 ; --i)
    {
        for(int j = i+1 ; j <= n-i ; ++j)
        a[j]--;
        for(int j = 1 ; j <= n ; ++j)
        {
            cout << a[j];  
        }
        cout << endl;
    }
    int k=n;
    for(int j = 1 ; j <= c/2 && k >= 1; ++j)
    {
        s=s+j*k*k;
        k=k-2;
    }
    cout << s;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.