Cod sursa(job #2110813)

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