题号:P1303
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<iostream> #include<algorithm> #include<string> #include<cstdlib> #include<cstring> #include<utility> using namespace std; int num1[5000], num2[5000], num3[5000]; char str1[5000], str2[5000]; int main(){ cin >> str1 >> str2; if (str1[0] == '0' || str2[0] == '0'){ cout << 0; return 0; } int len1 = strlen(str1) - 1, len2 = strlen(str2) - 1; for (int i = len1; i >= 0; i--)num1[len1 - i + 1] = str1[i] - '0'; for (int i = len2; i >= 0; i--)num2[len2 - i + 1] = str2[i] - '0'; len1++; len2++; for (int i = 1; i <= len1; i++){ for (int j = 1; j <= len2; j++){ num3[i + j - 1] += num1[i] * num2[j]; } } int i; for (i = 1; i<=len1+len2-1; i++){ num3[i + 1] += num3[i] / 10; num3[i] %= 10; } for (int i = len1 + len2 - 1; i >= 1; i--){ cout << num3[i]; } } |