加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

大数加法

发布时间:2020-12-14 03:52:18 所属栏目:大数据 来源:网络整理
导读:hdoj 1715 斐波那契+大数加法 #includeiostream#includecstdio#includecstringusing namespace std;int a[212],b[212],ans[212];int main(){ int n; int i,j,x; scanf("%d",n); while(n--) { scanf("%d",x); memset(a,sizeof(a)); memset(b,sizeof(b)); mems

hdoj 1715 斐波那契+大数加法

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[212],b[212],ans[212];
int main()
{
    int n;
    int i,j,x;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&x);
        memset(a,sizeof(a));
        memset(b,sizeof(b));
        memset(ans,sizeof(ans));

        a[0] = 1;
        b[0] = 1;
        if(x <= 2)
        {
            printf("1n");
            continue;
        }

        for(i = 3; i <= x; i++)
        {
            for(j = 0; j < 220; j++)
            {
                ans[j] = a[j] + b[j];
                if(ans[j] >= 10)
                {
                    a[j+1]++;
                    ans[j]-=10;
                }
            }
            for(j = 0; j < 220; j++)
            {
                a[j] = b[j];
                b[j] = ans[j];
            }
        }
        for(i = 220; i >= 0; i--)
            if(ans[i] != 0)
                break;
                int num = 0;
        for(; i >= 0; i--)
            {
                printf("%d",ans[i]);
                //num++;
            }
        printf("n");
        //cout<<num<<endl;
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读