题解 | #数列计数#
数列计数
https://www.nowcoder.com/practice/ef3b7b1b21d24d07a224e03a562f12d1
官方视频中的BigNumber 我用string实现
struct BigNumber{
string num;
BigNumber& operator=(const string &s){
num=s;
return *this;
}
BigNumber operator+(const BigNumber &b){
BigNumber ans;
string n=b.num;
int i=num.size()-1;
int j=n.size()-1;
int carry=0;
while (i>=0||j>=0) {
int a=i>=0?num[i--]-'0':0;
int b=j>=0?n[j--]-'0':0;
int sum=a+b+carry;
ans.num.push_back(sum%10+'0');
carry=sum/10;
}
if(carry>0)
ans.num.push_back(carry+'0');
reverse(ans.num.begin(), ans.num.end());
return ans;
}
friend ostream & operator<<(ostream &out, const BigNumber &b);
};
ostream & operator<<(ostream &out, const BigNumber &b){
out<<b.num;
return out;
}