Sunday, May 1, 2016

Codeforces 118B - Present from Lena

#include<bits/stdc++.h>
#define i64 long long
#define mx(a,b,c) max(a,max(b,c))
#define mn(a,b,c) min(a,min(b,c))
#define eef else if
#define ff(i,s,e) for(int i=(s); i<e; i++)
#define ff2(i,s,e) for(int i=(s); i>=e; i--)
#define sf scanf
#define pf printf
#define dbug(x) cout<<"x = "<<x<<endl
#define newl cout<<"\n"
#define putcase cout<<"Case "<<++cse<<":"
#define putcase2 cout<<"Case #"<<++cse<<":"
using namespace std;
int loop(int n , int limit)
{
    int temp;

    for(int j=0; j<=limit; j++){
        for(int k=n*2; k>0; k--){
            cout<<" ";
        }
        for(int l=0; l<=j; l++){

            if(l!=0)
                cout<<" ";
            cout<<l;
            temp=l;
        }
        for(int m=temp-1; m>=0; m--){
                cout<<" ";
                  cout<<m;
        }
          n--;
        cout<<endl;
    }
}
int pool(int n , int limit)
{
    int temp=limit-1 , var;
    for(int j=0; j<=limit; j++){
        for(int k=0; k<=j*2; k++)
            cout<<" ";
         for(int l=0; l<=temp; l++){

                cout<<" ";
                   cout<<l;
            var=l;
    }
    for(int m=var-1; m>=0; m--)
            cout<<" "<<m;
        temp--;
    if(j!=limit)
        cout<<endl;
    }

}
int main()
{
    int n;
    while(cin>>n){
        loop(n,n);
        pool(n,n);
    }


    return 0;
}

No comments:

Post a Comment