Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
15677 huyanfeng 高精度乘法 C++ 通过 0 MS 268 KB 738 2023-04-28 11:07:51

Tests(1/1):


#include<bits/stdc++.h> using namespace std; string s1, s2; int a[2010], b[2010], c[2 * 2010]; int main() { cin >> s1 >> s2; int len1 = s1.size(), len2 = s2.size(); for (int i = 0; i < len1; i++) { a[len1 - i] = s1[i] - '0'; } for (int i = 0; i < len2; i++) { b[len2 - i] = s2[i] - '0'; } for (int i = 1; i <= len1; i++) { for (int j = 1; j <= len2; j++) { c[i + j - 1] = a[i] * b[j] + c[i + j - 1];//之前的也要加上 } } int lenz = len1 + len2; int jin = 0; for (int i = 1; i <= lenz; i++) { int x = c[i] + jin; c[i] = x % 10; jin = x / 10; } while(c[lenz] == 0 && lenz != 1) { lenz--; } for (int i = lenz; i >= 1; i--) { cout << c[i]; } return 0; }


测评信息: