请问这个代码为啥的漏洞是哪里.....
#include <iostream>
#include <string>
using namespace std;
class BigInt
{
private:
string bigint;
public:
BigInt(string a="") { bigint= a; }
friend ostream & operator<< (ostream &os, const BigInt &a) {
os << a.bigint;
return os; }
friend istream& operator>>(istream &is, BigInt &x)//输入
{
is >> x.bigint;
return is;
}
BigInt operator +(BigInt &a)
{
string templong;
string tempshort;
bool jinwei=false;
string sum;
if (a.bigint.size() > bigint.size())
{
templong = a.bigint;
tempshort = bigint;
}
else {
templong = bigint;
tempshort = a.bigint;
}for (int i =1 ; i <=tempshort.size(); i++)
{
int l, s;
l = templong[templong.size() - i] - '0';
s = tempshort[tempshort.size() - i] - '0';
if (jinwei) {
jinwei = false;
if (s+l+1> 9) {
jinwei = true;
sum = to_string((s+l+1)% 10) + sum;
}
else { sum = to_string((s+l+1)) + sum; }
}
else {
if ((s+l)> 9) {
jinwei = true;
sum = to_string((s+l) % 10) + sum;
}
else { sum =to_string((s+l)) + sum; }
}
}
for (int i = tempshort.size()+1; i <= templong.size(); i++)
{
int l;
l = templong[templong.size() - i] - '0';
if (jinwei)
{ jinwei = false;
if ((l + 1) > 9)
{
jinwei = true;
sum = to_string((l+1) % 10) + sum;
}
else
{
sum = to_string(l + 1) + sum;;
}
}
else
{
sum = to_string(l) + sum; }
}
return BigInt(sum);
}
};
int main() {
BigInt a, b, c;
cin >> a >> b;
c = a + b;
cout << a << "+" << b << "=" << c << endl;
return 0;
}
我在pta的时候这个题目显示我部分正确,但是我想不到错误的地方。。。求大佬纠一下错。。。