模板:大整数加法

 1 string sum(string s1,string s2)
 2 {
 3     if(s1.length()<s2.length())
 4     {
 5         string temp=s1;
 6         s1=s2;
 7         s2=temp;
 8     }
 9     int i,j;
10     for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--)
11     {
12         s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0));   //注意细节
13         if(s1[i]-'0'>=10)
14         {
15             s1[i]=char((s1[i]-'0')%10+'0');
16             if(i) s1[i-1]++;
17             else s1='1'+s1;
18         }
19     }
20     return s1;
21 }

参考资料

http://blog.csdn.net/hp_justdoit/article/details/8297003

原文地址:https://www.cnblogs.com/mobileliker/p/3512632.html