435C codeforces - cardiogram


435C codeforces - cardiogram


http://codeforces.com/contest/435/problem/C




Solution in C++


#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
#define pii pair<int,int>

int n;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;
    int nn[n+1],mm[n+1];
    mm[0]=0;
    for(int i=1;i<=n;i++)
    {
        mm[i]=0;
        cin>>nn[i];
        if(i%2)mm[i]=mm[i-1]+nn[i];
        else mm[i]=mm[i-1]-nn[i];
    }
    int mn=*min_element(mm,mm+n+1);
    if(mn<0)for(int i=1;i<=n;i++)mm[i]-=mn;

    int mx=*max_element(mm,mm+n+1);
    for(int i=mx;i>0;i--)
    {
        for(int o=1;o<=n;o++)
        {
            if(mm[o]==i && o%2)
            {
                if(n%2 && o==n)cout<<string( nn[o]-1 ,' ' )<<"/";
                    else cout<<string( nn[o]-1 ,' ' )<<"/\\"<<string(nn[o+1]-1,' ');
            }
            else if(i<mm[o] && i>mm[o]-nn[o] && o%2)
                cout<<string(i- (mm[o]-nn[o]+1),' ')<<"/"<<string(mm[o]-i,' ');
            else if( o%2==0)
            {
             if(i>mm[o]+nn[o] || i<mm[o]+1)cout<<string(nn[o],' ');
             else if(i!=mm[o]+nn[o])cout<<string(mm[o]+nn[o]-i,' ')<<"\\"<<string(i-mm[o]-1,' ');
            }
            else cout<<string(nn[o],' ');
        }
        cout<<"\n";
    }
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق