Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- string multiply_big_integer(string A, string B) {
- int sz_a = (int) A.size();
- int sz_b = (int) B.size();
- vector<int> v(sz_a + sz_b, 0);
- for(int i = sz_a - 1; i >= 0; i--) {
- for(int j = sz_b - 1; j >= 0; j--) {
- v[i + j + 1] += (A[i] - '0') * (B[j] - '0');
- }
- }
- for(int i = sz_a + sz_b - 1; i >= 0; i--) {
- if(v[i] > 9) {
- v[i - 1] += (v[i] / 10);
- v[i] %= 10;
- }
- }
- int i = 0;
- while(v[i] == 0) {
- i++;
- }
- string product = "";
- for(int j = i; j < sz_a + sz_b; j++) {
- product += (v[j] + '0');
- }
- return product;
- }
- int main()
- {
- string a, b;
- cin >> a >> b;
- cout << multiply_big_integer(a, b) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement