数据下下来本地是对的,找不到溢出的地方qaq,求dalao看看为什么会re (可能写的有点乱请见谅,这个弄懂我就去背模板)
#include<iostream>
#include<cstring>
using namespace std;
int lef=0,dow=504;
int tplus(char a,char b){
int ma = int(a) - int('0') ;
int mb = int(b) - int('0') ;
return ma+mb ;
}
string hplus(string ha,string hb){
string a,b;
int temp[504]={0};
int l,ls;
int lha = ha.size(),lhb=hb.size() ;
if(lha>lhb||(lha==lhb&&a>b)){
a = ha;b=hb;l=lha;ls = lhb;
}else{
a = hb; b=ha;
l = lhb;ls = lha;
}
string c;
for(int i=0;i<l;++i){
if(ls-i>0){
temp[l-i]+=tplus(a[l-i-1],b[ls-1-i]);
if(temp[l-i]>=10){
temp[l-i-1]++;
temp[l-i] = temp[l-i]%10;
}
}else{
temp[l-i]+=int(a[l-i-1])-int('0');
if(temp[l-i]>=10){
temp[l-i-1]++;temp[l-i] = temp[l-i]%10;
}
}
}
if(temp[0]){
for(int i=0;i<=l;++i){
c[i]=char(temp[i]+int('0'));
dow = i;
}
}else{
for(int i=0;i<l;++i){
c[i]=char(temp[i+1]+int('0'));
dow =i;
}
}
return c ;
}
int main(){
string a,b;
cin>>a>>b;
string c = hplus(a,b) ;
for(int j=lef;j<dow+1;++j){
cout<<c[j];
}
return 0;
}