1
안녕하세요 큰 정수 클래스에서 작업하고 추가 및 뺄셈을 마쳤습니다 및 지금 현재 작업 곱하기 함수를 작성하려고하지만 첫 번째 3 자리 뒤에 정말 큰 숫자를 곱한 경우 정밀도가 떨어지고 대답이 잘못되었습니다. 아무도 내가 여기서 잘못하고있는 것을 도울 수 없었습니다. 나는 아무것도 생각할 수 없습니까?큰 정수 곱
BigInt operator*(const BigInt& left, const BigInt& right)
{
BigInt temp1 = left;
BigInt temp2 = right;
temp1.sign = 1;
temp2.sign = 1;
BigInt Max = MAX(temp1, temp2), Min = MIN(temp1, temp2);
ArrayList<char> temp_container = ArrayList<char>();
ArrayList<BigInt> nums = ArrayList<BigInt>();
int carry = 0;
int zero_count = 0;
for (int i = Min.Digits.size() - 1; i > -1; i--)
{
for (int j = Max.Digits.size() - 1; j > -1; j--)
{
int temp = (Max.Digits.get(j) * Min.Digits.get(i)) + carry;//Multiply Digits
if (temp < 10)//if it is a digit
{
temp_container.add_to_front(temp + '0');
carry = 0;
}
//else if it isnt a digit
else if (temp >= 10 && j > 0)
{
temp_container.add_to_front((temp/10) + '0');
carry = temp % 10;
}
else if (temp >= 10 && j < 0)
{
temp_container.add_to_front((temp/10) + '0');
temp_container.add_to_front((temp % 10) + '0');
}
}
for (int j = 0; j < zero_count; j++)
{
temp_container.add('0');
}
nums.add(BigInt(temp_container));
temp_container.removeAll();
zero_count++;//increase the amount of zeros to add to the next number
}
BigInt result = BigInt("0");
for (int i = 0; i < nums.size(); i++)
{
result += nums.get(i);//add all of the number up
}
//determine if positive or negative
if (left.sign == right.sign)
{
result.sign = 1;
}
else
{
result.sign = -1;
}
return result;
}
와우 나는 그 감사를 보지 못했다고 나는 믿을 수 없다. – user3000477
@ user3000477 : 답변으로 표시한다. – kec