A+B

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int MAXLEN = 30;

char *addition(char *m1, char *m2)
{
	int i, len1, len2, len, c=0;
	int * t1, * t2;
	len1=strlen(m1);len2=strlen(m2);
	len=(len1>=len2)?len1:len2;  //定位數
	t1=new int[(len+2)*sizeof(int)];
	t2=new int[(len+2)*sizeof(int)];
	t1=Str2Int(m1);
	t2=Str2Int(m2);
	for(i=len1;i<len+1;i++) t1[i]=0; //缺位前導補零
	for(i=len2;i<len+1;i++) t2[i]=0; //缺位前導補零
	for(i=0;i<len;i++) t1[i]=t1[i]+t2[i]; //加法
	len=check(t1,len); // 歸整
	return Int2Str(t1,len); //轉化爲字符串,返回
}

int main()
{
	char s1[MAXLEN], s2[MAXLEN];
	while(cin>>s1>>s2)
		cout<<addition(s1,s2)<<endl;//
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章