大数相乘

#include <iostream>
#include <string>
using namespace std;

/* 请在这里填写答案 */
class BigInteger{
    protected:
    int a[3005];
    int count;
    public:
    BigInteger(){
        for(int i=0;i<3005;i++){
            a[i]=0;
        }
        count=0;
    }
    friend BigInteger operator *(BigInteger &a,BigInteger &b){
        BigInteger c;
        int k=a.count+b.count;
        for(int i=a.count-1;i>=0;i--){
            for(int j=b.count-1;j>=0;j--){
                c.a[i+j+1]+=a.a[i]*b.a[j];
                if(c.a[i+j+1]>9){
                    c.a[i+j]+=c.a[i+j+1]/10;
                    c.a[i+j+1]%=10;
                }
            }
        }
        c.count=k;
        return c;
    }
    friend istream& operator >> (istream &in,BigInteger &s){
        string s1;
        in>>s1;
        for(int i=0;i<s1.size();i++){
            s.a[i]=s1[i]-‘0‘;
            s.count++;
        }
        return in;
    }
    friend ostream& operator << (ostream &o,BigInteger &s){
        int flag=1;
        for(int i=0;i<s.count;i++){
            if(s.a[i]!=0){
                flag=0;
            }
            if(flag==0){
                o<<s.a[i];
            }
        }
        if(flag==1){
            o<<"0";
        }
        return o;
    }
};

int main() 
{
    BigInteger a, b, c;
    cin >> a >> b;
    c = a * b;
    cout << a << "*" << b << "=" << c << endl;
    return 0;
}


大数相乘

上一篇:解决element的el-input 输入框浏览器自动填充账号密码问题


下一篇:手动开平方根