Cod sursă (job #439328)

Utilizator avatar TheodorVlad Paraschiv Theodor Vlad TheodorVlad IP ascuns
Problemă 2sah (clasele 11-12) Compilator cpp | 1,25 kb
Rundă Arhiva de probleme Status evaluat
Dată 26 feb. 2019 11:51:13 Scor 24
#include <iostream>
#include <fstream>
using namespace std;
int a[1000][1000]={0};
int main()
{
    int v,n,i,k;
    ifstream f("2sah.in");
    ofstream g("2sah.out");
    f>>v;
    f>>n;
    f>>k;
    if (v==1)
    {
        int p=1;
        for (i=1;i<=k-1;i++)
            {
                p*=3;
                p=p%100003;
            }
        g<<p;

    }
    else
    {
    int j;
    a[1][n+1]=1;
    a[2][n]=1;
    a[2][n+1]=1;
    a[2][n+2]=1;
    int x=n-1;
    int y=n+3;
    for (i=3;i<=n+1;i++)
    {
        a[i][x]=1;
        x--;
        a[i][y]=1;
        y++;
        for (j=x+1;j<=n+1;j++)
        if (j!=n+1)
        {
            a[i][j]=a[i-1][j-1]+a[i-1][j]+a[i-1][j+1];
            a[i][2*n+2-j]=a[i][j];
        }
        else
            a[i][j]=a[i-1][j]+2*a[i-1][j-1];

    }

    for (i=1;i<=n+1;i++)
    {
        for (j=1;j<=2*n+1;j++)
            cout<<a[i][j]<<" ";
        cout<<endl;
    }
    i=1;
    j=k;
    int c=0;
    int s=0;
    while (c!=2)
    {
        if (a[i][j]!=0)
            c=1;
        s+=a[i][j];
        i++;
        j=j+2;
        if ((c==1) && (a[i][j]==0))
            c=2;
    }
    g<<s;
    }
    f.close();
    g.close();
    return 0;
}