Cod sursa(job #1821245)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 2 decembrie 2016 20:33:42
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <cstring>
std::ofstream t ("nunta.out");
struct hugeVal{
private:
    short index;
    static unsigned const short SIZE=0x100;
public:
    short num[SIZE]{0};
    inline hugeVal &operator = (hugeVal n){
        memcpy(num,n.num,SIZE);
        return *this;}
    inline hugeVal &operator += (hugeVal target){
        bool remainder=0;
        for (index=0;index<SIZE;++index){
            num[index]+=remainder+target.num[index];
            if (num[index]>9)
                remainder=1,num[index]%=10;
            else remainder=0;}
        return *this;
    }
    void print(){
        index=SIZE-1;
        while (!num[index]) --index;
        while (index>=0) t<<num[index],--index;
        }
};
int main()
{
    std::ifstream f ("nunta.in");
    std::ios_base::sync_with_stdio(false);
    short n;
    f>>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;
}