Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
168699 A班匡嘉阳 高精度乘法 C++ 通过 100 16 MS 15928 KB 835 2024-08-20 13:20:17

Tests(30/30):


#include <bits/stdc++.h> using namespace std; char a1[5001],b1[5001]; int a[5001],b[5001],c[4000005],x,t,k; bool sign = 0; int main(){ memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); cin >> a1 >> b1; k = strlen(a1) + strlen(b1); for(int i = 0;i < strlen(a1);i++){ a[i + 1] = a1[strlen(a1) - i - 1] - 48; } for(int i = 0;i < strlen(b1);i++){ b[i + 1] = b1[strlen(b1) - i - 1] - 48; } for(int i = 1;i <= strlen(a1);i++){ x = 0; for(int j = 1;j <= strlen(b1);j++){ t = a[i] * b[j]; c[i + j - 1] = t % 10 + x + c[i + j - 1]; x = t / 10; if(c[i + j - 1] >= 10){ x += c[i + j - 1] / 10; c[i + j - 1] %= 10; } } c[i + strlen(b1)] = x; } for(int i = k;i > 0;i--){ if(c[i] != 0) sign = 1; if(sign || i == 1) cout << c[i]; } return 0; }


测评信息: