C/C++

Помогите написать код! С++ Строки (без использования классов)

В двух данных строках заданы два довольно длинных натуральных числа (таких, которые не уместятся в стандартные целые типы данных). Найти и вывести в файл запись нахождения их произведения, выполненного столбиком.
 #include    
using namespace std;

string multiple(const string& l, const char ch)
{
string result;
int add = 0;
int num;
for (auto i = l.crbegin(); i != l.crend(); i++)
{
num = (ch - '0') * (*i - '0') + add;
result.push_back(num % 10 + '0');
add = num / 10;
}
if (add != 0) result.push_back(add + '0');
reverse(result.begin(), result.end());
return result;
}

string add(const string& l, const string& r)
{
string result;
bool left = true, right = true;
int num, add = 0;
auto l_it = l.crbegin();
auto r_it = r.crbegin();
do
{
num = (left?*l_it - '0':0) + (right?*r_it - '0':0) + add;
result.push_back(num % 10 + '0');
add = num / 10;
if (left)
{
l_it++;
left = l_it != l.crend();
}
if (right)
{
r_it++;
right = r_it != r.crend();
}
} while (left || right);
if (add != 0) result.push_back(add + '0');
reverse(result.begin(), result.end());
return result;
}

int main()
{
bool negative{};
string a, b, tmp, result = "0";
cin >> a >> b;
if (a.length() < b.length()) swap(a, b);
if (a[0] == '-')
{
a = string(a.begin() + 1, a.end()); negative = !negative;
}
if (b[0] == '-')
{
b = string(b.begin() + 1, b.end()); negative = !negative;
}
int m10 = 0;
for (auto b_it = b.crbegin(); b_it != b.crend(); b_it++)
{
tmp = multiple(a, *b_it);
tmp.append(m10, '0');
m10++;
result = add(result, tmp);
}
if (negative) result = '-' + result;
cout
OS
Omurbek Shamshiev
51 416
Лучший ответ