大数求和

185 阅读1分钟

 

描述: 

给定两个非常大的正整数A和B,位数在50至100之间。求C=A+B;

 

题目类别: 字符串 
难度: 中级 
运行时间限制: 10Sec 
内存限制: 128MByte 

输入: 

因为A和B很大,从高位到低位,以字符串的形式输入两行数字A和B。A和B的位数在50至100之间。

 

输出: 
以字符串形式,输出一行,表示A和B的和。

 

样例输入: 

111111111111111111111111111111111111111111111111111111111
22222222222222222222222222222222222222222222222222

 

 

样例输出: 

33333333333333333333333333333333333333333333333333

 

代码:

 

#include<iostream>
#include<string>
using namespace std;

string add(string s1, string s2) {
	int length1 = s1.size();
	int length2 = s2.size();
	if (length1 == 0 && length2 !=0) {
		return s2;
	}
	if (length1 != 0 && length2 == 0) {
		return s1;
	}
	if (length1 == 0 &am