1 条题解

  • 0
    @ 2024-8-15 10:00:09
    #include<bits/stdc++.h>
    using namespace std;
    long long num1; string qwq,g = "1",h;
    int a1[100005],a2[100005],len1,len2,a[200005],len;
    string cheng(string num1,string num2){
    	string str = "";
    	if(num1 == "0" || num2 == "0"){
    		str = "0";
    		return str;
    	}
        memset(a1,0,sizeof a1);
    	memset(a2,0,sizeof a2);
    	memset(a,0,sizeof a);
    	len1 = num1.size();
        for (int i = 0; i < len1;i++) {
            a1[i] =num1[len1-1-i] - '0';
        }
        len2 = num2.size();
        for (int i = 0; i < len2;i++) {
            a2[i]=num2[len2-1-i]-'0';
        }
        for (int i = 0; i < len1;i++) {
            for (int j = 0; j < len2;j++){
            	a[i + j] += a1[i] * a2[j];
            }
        }
        len = len1 + len2 - 1;
        for (int i = 0; i < len; i++) {
            a[i + 1] += a[i] / 10;
            a[i] %= 10;
        }
        while (a[len]) {
            a[len + 1] += a[len] / 10;
            a[len] %= 10;
            len++;
        }
        for (int i = len - 1; i >= 0; i--) {
            str += a[i]+'0';
        }
        return str;
    }
    int main() {
        freopen("bigmul.in", "r", stdin);
        freopen("bigmul.out", "w", stdout);
        long long a;
        string s1,s2;
        scanf("%lld",&a);
        for(int i = 1;i <= a;i++){
        	cin >> s1 >> s2;
        	cout << cheng(s1,s2) << endl;
    	}
        return 0;
    }
    
    • 1

    信息

    ID
    428
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    127
    已通过
    27
    上传者