Home > Back-end >  B: where is this code is what holes...
B: where is this code is what holes...

Time:09-18

# include & lt; Iostream>
# include & lt; String>

using namespace std;

The class BigInt
{
Private:
String bigint,
Public:
BigInt (string a="") {BigInt=a; }
Friend ostream & amp; Operator<(ostream & amp; OS, const BigInt & amp; A) {
OS & lt; Return the OS; }
Friend istream& Operator> (cost & amp; The BigInt & amp; X)//input
{
Is & gt;> X.b igint;
The return is;
}
BigInt operator + (BigInt & amp; A)
{
String templong;
String tempshort;
Bool jinwei=false;
String sum;
If (a. igint. The size () & gt; Bigint. The size ()
{
Templong=a. igint;
Tempshort=bigint;
}
The else {
Templong=bigint;
Tempshort=a. igint;
} the for (int I=1; I & lt;=tempshort. The size (); I++)
{
Int l, s;
L=templong [templong. The size () - I] - '0';
S=tempshort [tempshort. The size () - I] - '0';
If (jinwei) {
Jinwei=false;

If (s + l + 1 & gt; 9) {
Jinwei=true;
Sum=to_string (10) (s + l + 1) % + sum;
}
The else {sum=to_string ((s + l + 1)) + sum; }
}
The else {
If ((s + l) & gt; 9) {
Jinwei=true;
Sum=to_string (10) (s + l) % + sum;
}
The else {sum=to_string ((s + l)) + sum; }
}
}
For (int I=tempshort. The size () + 1; I & lt;=templong. The size (); I++)
{
Int l;
L=templong [templong. The size () - I] - '0';
If (jinwei)
{jinwei=false;
If ((l + 1) & gt; 9)
{
Jinwei=true;
Sum=to_string (10) (l + 1) % + sum;

}
The else
{

Sum=to_string (l + 1) + sum;;
}
}
The else
{
Sum=to_string (l) + sum; }
}



Return BigInt (sum);
}

};
Int main () {
BigInt a, b, c;
cin> a> b;
C=a + b;
cout CodePudding user response:

At least explain the background of the problem, otherwise no one has time to help you debug code

CodePudding user response:

reference 1/f, pearling response:
at least explain the background of the problem, otherwise no one will have time to help you debug code

Is to implement two input can be greater than the size of the integer Numbers (i.e., as a string input), and then add and subtract by location, at the same time use logic to carry an integer arithmetic... , the new question, sorry...
  • Related