(快考试了,复习下)
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 //此处的高精加不考虑负数 6 using namespace std; 7 struct bignum{ 8 int y[50005];//第0位存size 9 //全部为倒存(节省点常数) 10 bignum() 11 {memset(y,0,sizeof(y));} 12 bignum operator + (const bignum x) const 13 { 14 bignum re; 15 re.y[0]=max(y[0],x.y[0]); 16 for(int i=1;i<=re.y[0];i++) 17 { 18 re.y[i]+=y[i]+x.y[i]; 19 while(re.y[i]>9) re.y[i]-=10,re.y[i+1]+=1; 20 } 21 while(re.y[re.y[0]+1]) re.y[0]++; 22 return re; 23 } 24 }; 25 string b1,b2; 26 bignum q,w,c; 27 int main() 28 { 29 cin>>b1>>b2; 30 q.y[0]=b1.size(),w.y[0]=b2.size(); 31 for(int i=0;i<q.y[0];i++) q.y[i+1]=b1[i]-'0'; 32 for(int i=0;i<w.y[0];i++) w.y[i+1]=b2[i]-'0'; 33 reverse(q.y+1,q.y+1+q.y[0]); 34 reverse(w.y+1,w.y+1+w.y[0]); 35 c=q+w; 36 reverse(c.y+1,c.y+1+c.y[0]); 37 for(int i=1;i<=c.y[0];i++) printf("%d",c.y[i]); 38 return 0; 39 }