zoukankan      html  css  js  c++  java
  • 密码【高精】

    题目大意:
    输入n个不大于1024的数字,求它们的积。

    Input

    3
    12
    34
    56

    Output

    22848

    思路:

    高精乘高精

    题目上写“不超过1024“,全体以为高精乘单精,30分。。。
    模板高精乘,直接上代码。


    代码:

    #include <cstdio>
    #include <iostream>
    #include <string>
    using namespace std;
    
    const int maxn=2400;
    int a[maxn+1],b[maxn+1],c[maxn+1],n,size,t,m;
    string s;
    
    int main()
    {
        scanf("%d",&n);
        a[1]=1;  //初始化
        while (n--)
        {
            for (m=maxn;m;m--)
             if (a[m]) break;  //求a数组的长度
            cin>>s;
            size=s.size();
            for (int i=0;i<=size-1;i++)
             b[size-i]=(int)s[i]-48;  //倒序储存
            for (int i=1;i<=m;i++)  //序列a
            {
                t=0;
                int j;
                for (j=1;j<=size;j++)  //序列b
                {
                    c[i+j-1]+=a[i]*b[j]+t;
                    t=c[i+j-1]/10;
                    c[i+j-1]%=10;  //高精乘模板
                }
                c[size+i]=t;  //进位
            } 
            for (int i=1;i<=maxn;i++)  //重新储存
            {
                a[i]=c[i];
                c[i]=b[i]=0;  //清零
            }
        }
        int i=maxn;
        while (a[i]==0) i--;
        for (int j=i;j>=1;j--)
         printf("%d",a[j]);  //倒序输出
        return printf("\n")&0;
    }
  • 相关阅读:
    套题 codeforces 361
    hdu 5720
    套题 codeforces 360
    套题 codeforces 359
    套题 bestcoder 84
    hdu 5748(求解最长上升子序列的两种O(nlogn)姿势)
    观django-messages包笔记
    django form
    省份、城市、区县三级联动Html代码
    django perm用法
  • 原文地址:https://www.cnblogs.com/hello-tomorrow/p/9313047.html
Copyright © 2011-2022 走看看