提交时间:2024-08-20 08:12:08
运行 ID: 168218
#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; }