哪位大佬能帮忙看看高精度加减乘除模是否有问题
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
string clearZeros(string data)
{
if (data[0] == '0') {
int key = (int) data.length() - 1;
for (int i = 0; i < data.length(); i++) {
if (data[i] != '0') {
key = i;
break;
}
}
data.erase(0, key);
}
if (data == "") {
data = "0";
}
return data;
}
void countPoint(string &operand1, string &operand2)
{
while (operand1.length() < operand2.length()) {
operand1 = "0" + operand1;
}
while (operand1.length() > operand2.length()) {
operand2 = "0" + operand2;
}
}
bool bigger(string operand1, string operand2)
{
return operand1 >= operand2;
}
string addition(string addent, string adder)
{
//先对位,在加数和被加数前面适当补0,使他们包含相同的位数
countPoint(addent, adder);
//前面再补一个0,确定和的最多位数
addent = "0" + addent;
adder = "0" + adder;
//从低位开始,对应位相加,结果写进被加数中,如果有进位,直接给被加数前一位加1
for (int i = (int) addent.length() - 1; i > 0; i--) {
addent[i] = addent[i] + adder[i] - 48;
if (addent[i] > '9') {
addent[i] = addent[i] - 10;
addent[i - 1] = addent[i - 1] + 1;
}
}
return clearZeros(addent);
}
string subtraction(string subtrahend, string subtractor)
{
//先对位,在减数和被减数前面适当补0,使他们包含相同的位数
countPoint(subtrahend, subtractor);
//判断被减数和减数谁大,保证被减数大于减数
if (bigger(subtrahend, subtractor)) {
subtrahend[0] = subtrahend[0] - subtractor[0] + 48;
for (int i = 1; i < (int)subtrahend.length(); i++) {
if (subtrahend[i] >= subtractor[i]) {
subtrahend[i] = subtrahend[i] - subtractor[i] + 48;
} else {
subtrahend[i] = subtrahend[i] - subtractor[i] + 10 + 48;
subtrahend[i - 1]--;
}
}
} else {
subtrahend = '-' + subtraction(subtractor, subtrahend);
}
return subtrahend;
}
string multiplication(string multiplicand, string multiplier)
{
string result = "0";
for (int i = (int)multiplier.length() - 1; i >= 0 ; i--) {
for (char c = '1'; c <= multiplier[i]; c++) {
result = addition(result, multiplicand);
}
multiplicand = multiplicand + "0";
}
return clearZeros(result);
}
string division(string dividend, string divisor, bool type = 0)
{
string result;
string resmod;
for (register int i = 0; i < divisor.size() - 1; ++i) resmod += dividend[i];
for (register int i = divisor.size() - 1; i < dividend.size() ; ++i)
{
resmod += dividend[i];
result += '0';
while (subtraction(resmod, divisor) >= "0")
{
++result[result.size() - 1];
resmod = subtraction(resmod, divisor);
}
result = clearZeros(result);
resmod = clearZeros(resmod);
}
if (!type) return result;
else return resmod;
}
string mod(string dividend, string modster)
{
return division(dividend, modster, true);
}
string gcd(string a, string b)
{
if (b == "0") return a;
else return gcd(b, mod(a, b));
}
int main()
{
string a, b, c;
cin >> a >> b >> c;
cout << gcd(addition(a, c), b);
return 0;
}