Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Last active June 28, 2018 17:43
Show Gist options
  • Save MohamedTaha98/86fd4854e6b9d92d79c5f2681d5ce85c to your computer and use it in GitHub Desktop.
Save MohamedTaha98/86fd4854e6b9d92d79c5f2681d5ce85c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
string s, t;
while(cin >> s)
{
cin >> t;
vector<int> v1, v2;
for (int i = 0; i < (int)s.length(); i++)
v1.resize(v1.size() + 1, s[i] - '0');
for (int i = 0; i < (int)t.length(); i++)
v2.resize(v2.size() + 1, t[i] - '0');
reverse(v1.begin(), v1.end()); reverse(v2.begin(), v2.end());
if (v1.front() != 0 && v2.front() != 0)
{
vector<int> v3(v1.size() + v2.size(), 0);
for (int i = 0; i < (int)v1.size(); i++)
{
for (int j = 0; j < (int)v2.size(); j++)
v3[i + j] += v1[i] * v2[j];
}
for (int i = 0; i < (int)v3.size() - 1; i++)
{
v3[i + 1] += (v3[i] / 10);
v3[i] %= 10;
}
if (v3.back() == 0)
v3.erase(v3.end() - 1);
reverse(v3.begin(), v3.end());
for (int i = 0; i < (int)v3.size(); i++)
cout << v3[i];
}
else cout << 0;
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment