Cod sursa(job #2110821)

Utilizator Mihai145Oprea Mihai Adrian Mihai145 Data 21 ianuarie 2018 13:36:27
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>
#define CIFMAX 210
using namespace std;
short int n, a[CIFMAX], b[CIFMAX];
void add(short int t1[], short int t2[])
{
    int i, t=0;
    for(i=1; i<=t1[0] || t!=0; i++)
    {
        t2[i]=t2[i]+t1[i]+t;
        t=t2[i]/10;
        t2[i]%=10;
    }
    t2[0]=i-1;
}
int main()
{
    freopen("nunta.in","r",stdin);
    freopen("nunta.out","w",stdout);
    scanf("%d",&n);
    short int i;
    a[1]=1, b[1]=2, a[0]=1, b[0]=1;
    for(i=3; i<=n; i++)
        if(i%2==1) add(b,a);
        else add(a,b);
    if(n%2==1)
    {
        for(i=a[0]; i>=1; i--)
            printf("%d",a[i]);
    }
    else
    {
        for(i=b[0]; i>=1; i--)
            printf("%d",b[i]);
    }
    return 0;
}