Cod sursa(job #2023737)

Utilizator andreicoman299Coman Andrei andreicoman299 Data 19 septembrie 2017 13:55:13
Problema Nunta Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <stdio.h>
#include <stdlib.h>

#define MAXC 200

char F1[MAXC], F2[MAXC];

inline void add(char A[], char B[]){
      int i, t = 0;
      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(){
    FILE*fi,*fo;
    fi=fopen("nunta.in","r");
    fo=fopen("nunta.out","w");

    int n;
    fscanf(fi,"%d", &n);
    if(n == 1){
        fprintf(fo,"1");
        return 0;
    }

    F1[0] = 1;
    F1[1] = 1;

    F2[0] = 1;
    F2[1] = 2;

    int ind = 2;
    for(int i = 3; i <= n; i++){
        if(ind == 2)
            add(F1, F2);
        else
            add(F2, F1);
        ind = 3 - ind;
    }

    if(ind == 2)
        for(int i = F2[0]; i > 0; i--)
            fprintf(fo,"%d", F2[i]);
    else
        for(int i = F1[0]; i > 0; i--)
            fprintf(fo,"%d", F1[i]);

    fclose(fi);
    fclose(fo);
    return 0;
}