提交时间:2024-08-20 21:13:16

运行 ID: 172614

#include <bits/stdc++.h> using namespace std; char str1[5050], str2[5050]; int a1[5050] = {0}, b1[5050] = {0}, c[5050] = {0}, x; int main() { cin >> str1; cin >> str2; int lena = strlen(str1); int lenb = strlen(str2); for(int i = 0; i < lena; i++) a1[lena - i] = str1[i] - '0'; for(int i = 0; i < lenb; i++) b1[lenb - i] = str2[i] - '0'; for(int i = 1; i <= lenb; i++) { x = 0; for(int j = 1; j <= lena; j++) { c[i + j - 1] = a1[j] * b1[i] + x + c[i + j - 1]; x = c[i + j - 1] / 10; c[i + j - 1] = c[i + j - 1] % 10; } c[i + lena] = x; } int lenc = lena + lenb; while((c[lenc] == 0) && (lenc > 1)) lenc--; for(int i = lenc; i >= 1; i --) { printf("%d",c[i]); } return 0; }