提交时间:2024-08-20 15:45:47
运行 ID: 169219
#include <bits/stdc++.h> using namespace std; char a1[2500], b1[2500]; int a[2500], b[2500], c[5500000], x, t, k, i, j; bool flag = false; int main(){ memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); cin >> a1; cin >> b1; k = strlen(a1) + strlen(b1); for(i = 0; i < strlen(a1); i++){ a[i + 1] = a1[strlen(a1) - i - 1] - 48; } for(i = 0; i < strlen(b1); i++){ b[i + 1] = b1[strlen(b1) - i - 1] - 48; } for(i = 1; i <= strlen(a1); i++){ x = 0; for(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(i = k; i > 0; i--){ if(c[i] != 0) flag = true; if(flag || i == 1) cout << c[i]; } return 0; }