#5#6,qz

P1255 数楼梯

Tan_Transparent @ 2022-08-11 17:49:22

#include<bits/stdc++.h>
using namespace std;
#define maxn 100
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
struct fantastic     //开始重载了
{
    int len,s[9999];
    fantastic()
    {
        memset(s,0,sizeof(s));
        len=1;
    }
    fantastic operator=(const char*num)
    {
        len=strlen(num);
        for(int i=0;i<len;++i)
            s[i]=num[len-i-1]-'0';
        return *this;
    }
    fantastic operator=(const int num)
    {
        char a[9999];
        sprintf(a,"%d",num);
        *this=a;
        return *this;
    }
    fantastic (const int num)
    {
        *this=num;
    }
    fantastic (const char * num)
    {
        *this=num;
    }
    fantastic operator+(const fantastic &a) 
    {
        fantastic c;
        c.len=max(len,a.len)+1;       
        for(int i=0,x=0;i<c.len;++i)
        {
            c.s[i]=s[i]+a.s[i]+x;
            x=c.s[i]/10;
            c.s[i]=c.s[i]%10;
        }
        if(c.s[c.len-1]==0)
            --c.len;
        return c;
    }
    fantastic operator * (const fantastic &x)
    {
        fantastic c;
        c.len=len+x.len;
        for(int i=0;i<len;++i)
            for(int j=0;j<x.len;++j)
            {
                c.s[i+j]+=s[i]*x.s[j];
                c.s[i+j+1]+=c.s[i+j]/10;
                c.s[i+j]%=10;
            }
        if(c.s[c.len-1]==0)
            --c.len;
        return c;
    }
};
ostream& operator<<(ostream &out,const fantastic& x)   //重载一下输出
{
    for(int i=x.len-1;i>=0;--i)
        cout<<x.s[i];
    return out;
}
istream& operator>>(istream &in,fantastic &x)       //重载一下输入
{
    char num[9999];
    in>>num;
    x=num;
    return in;
}
int main(){
    fantastic s1(1),s2(2),s3(0);
    int n;
    cin>>n;
    for(int i=1;i<=n-2;i++){
        s3=s1+s2;
        s1=s2;
        s2=s3;
    }
    cout<<s3;
}

by Tan_Transparent @ 2022-08-11 17:55:42

https://www.luogu.com.cn/record/83379078

https://www.luogu.com.cn/record/83379935

wa ou~


|