zoukankan      html  css  js  c++  java
  • SSLZYC 公牛数学

    题目大意:
    输入两个不大于10^40的数,输出它们的积。


    思路:
    很明显的一道高精乘。
    用数组a[i]和b[i]记录两个乘数,用c[i]记录答案。
    千万不要忘记用字符数组或字符串读入!


    代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    const int maxn=100;
    int a[maxn+1],b[maxn+1],c[maxn+1],n,m,t;
    char cha[maxn+1],chb[maxn+1],ch;
    
    int main()
    {
        freopen("bullmath.in","r",stdin);
        freopen("bullmath.out","w",stdout);
        cin>>cha;
        cin>>chb;  //读入两个乘数
        n=strlen(cha);
        m=strlen(chb);
        for (int i=0;i<n;i++)
         a[maxn-n+i]=cha[i]-48;
        for (int i=0;i<m;i++)
         b[maxn-m+i]=chb[i]-48;  //将字符转换成数组
        for (int i=maxn;i>=1;i--)  //高精乘
        {
            t=0;
            for (int j=maxn;j>=1;j--)
            {
                c[i+j-maxn]+=a[i]*b[j]+t;
                t=c[i+j-maxn]/10;
                c[i+j-maxn]%=10;
            }
        }
        int i=1;
        while (c[i]==0) i++;  //去除前导0
        for (int j=i;j<=maxn-2;j++)
         printf("%d",c[j]);
        return 0;
    }
  • 相关阅读:
    (转载)MySQL日期时间函数大全
    Tcl commands
    Toplevel
    tk 8.4 commands
    iwidgets
    Options for Buttontype widgets
    Text Widget Options
    tk options
    itk_option
    Widget Options
  • 原文地址:https://www.cnblogs.com/hello-tomorrow/p/9313109.html
Copyright © 2011-2022 走看看