这个是c++的,是两个整数相加的代码,代码如下#include
#include
#include
using namespace std;
int main()
{
string a,b;
cin>>a>>b;
string result = "";//存放结果
int ys=0;//余数
int i=0, j=0;
i = a.length()-1;
j = b.length()-1;
for (; i >= 0 || j >= 0; i--, j--)
{
if (i >= 0) ys += a[i]-'0';//字符转为数字是数字+48(‘0’)
if (j >= 0)ys += b[j]-'0';
result += (char)(ys % 10+'0');//转回字符
ys /= 10;
}
if (ys == 1)
result += '1';
reverse(result.begin(), result.end());
int len = result.length();
i = 0;
while (i<len)
{
if (result[i] != '0')//记录结果开头后多少0
{
break;
}
i++;
}
for (; i < len; i++)//越过结果开头为0输出
{
cout << result[i];
}
}