标签:
string strAdd(string &v1, string &v2){ string res = ""; int carry = 0; int len1 = v1.size(), len2 = v2.size(); for(int i = len1-1, j = len2-1; i >= 0 || j >= 0; i--, j--){ int n1 = (i >= 0) ? v1[i]-‘0‘ : 0; int n2 = (j >= 0) ? v2[j]-‘0‘ : 0; res = to_string((n1 + n2 + carry) % 10) + res; carry = (n1 + n2 + carry) > 9; } return (carry) ? "1" + res : res; }
标签:
原文地址:http://www.cnblogs.com/sweetiemelody/p/5032962.html