提交时间:2024-08-20 09:44:12

运行 ID: 168328

#include <cstring> #include <iostream> using namespace std; int main(){ char s1[2005],s2[2005]; long long a[2005] = {}, b[2005] = {}, c[2005] = {}; int lena, lenb, lenc; cin >> s1 >> s2; lena = strlen(s1); lenb = strlen(s2); for (int i = 0;i <= lena-1;i++){ a[i] = s1[lena-1-i] - '0'; } for (int i = 0;i <= lenb-1;i++){ b[i] = s2[lenb-1-i] - '0'; } for (int i = 0;i <= lena-1;i++){ for(int j = 0;j <= lenb-1;j++){ c[i+j] += a[i] * b[j]; c[i+j+1] += c[i+j] / 10; c[i+j] = c[i+j] % 10; } } lenc = lena + lenb; while(c[lenc-1] == 0 && lenc-1 > 0){ lenc--; } for (int i = lenc-1;i>=0;i--){ cout << c[i]; } return 0; }