Cod sursa(job #1821272)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 2 decembrie 2016 20:51:03
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <cstring>
#include <cstdio>
struct hugeVal{
public:
    short num[0x100]{0};
    inline hugeVal &operator = (hugeVal target){
        memcpy(num,target.num,0x100);
        return *this;}
    inline hugeVal &operator += (hugeVal target){
        bool remainder=0;
        for (short index=0;index<0x100;++index){
            num[index]+=remainder+target.num[index];
            if (num[index]>9)
                remainder=1,num[index]%=10;
            else remainder=0;}
        return *this;
    }
    void print(){
        FILE*t=fopen("nunta.out","w");
        short index=0xFF;
        while (!num[index]) --index;
        while (index>=0) fprintf(t,"%hd",num[index]),--index;
        }
};
int main()
{
    FILE*f=fopen("nunta.in","r");
    short n;
    fscanf(f,"%hd",&n);
    hugeVal a,b,aux;
    b.num[0]=1;
    LOOP:
        --n;
        aux=b;
        b+=a;
        a=aux;
        if (n>1) goto LOOP;
    b.print();
    return 0;
}