Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
168218 C班-张腾午 高精度乘法 C++ 通过 100 1 MS 264 KB 715 2024-08-20 08:12:08

Tests(30/30):


#include <iostream> #include <string> using namespace std; int a[1005], b[1005], ans[2005]; string s1, s2; int main() { int i, j, in = 0, len1, len2, lenans; cin >> s1 >> s2; len1 = s1.length(); len2 = s2.length(); for (i = 0; i <= len1 - 1; i++) a[i] = s1[len1 - 1 - i] - 48; for (i = 0; i <= len2 - 1; i++) b[i] = s2[len2 - 1 - i] - 48; for (i = 0; i <= len1 - 1; i++) { in = 0; for (j = 0; j <= len2 - 1; j++) { ans[i + j] += a[i] * b[j] + in; in = ans[i + j] / 10; ans[i + j] %= 10; } ans[len2 + i] = in; } lenans = len1 + len2; while (ans[lenans - 1] == 0 && lenans > 1) lenans--; for (i = lenans - 1; i >= 0; i--) cout << ans[i]; return 0; }


测评信息: