Cod sursa(job #1276404)

Utilizator hasmasandragosHasmasan Dragos hasmasandragos Data 26 noiembrie 2014 12:14:28
Problema Nunta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <cstdio>
using namespace std;

short int a[269],b[269];
int n;

void adunare (short int A[] ,short int B[])
{
    int t=0,i;
    for (i=1;i<=A[0] || i<=B[0] || t; i++ , t/=10)
    {
       A[i]=(t+=A[i]+B[i])%10;
    }
    A[0]=i-1;
}

int main()
{
    freopen("nunta.in", "r", stdin);
    freopen("nunta.out", "w", stdout);
    scanf("%d", &n);
    a[0]=1;
    b[0]=1;
    b[1]=1;
    int i;
    for (i=1;i<=n;i++)
        {
           if (i%2)
           adunare(a,b);
           else
           adunare(b,a);
        }
    if (n%2==0)
    for (i=b[0];i>=1;i--)
        printf("%d", b[i]);
    else
    for (i=a[0];i>=1;i--)
        printf("%d", a[i]);
    return 0;
}