记录编号 99046 评测结果 AAAAAAAAAA
题目名称 增强的加法问题 最终得分 100
用户昵称 GravatarOI永别 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2014-04-25 19:13:25 内存使用 0.31 MiB
显示代码纯文本
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

struct BIGNUM{
	int x[102];
	void clean(){
		memset(x,0,sizeof(x));
	}
	friend BIGNUM operator +(const BIGNUM & a,const BIGNUM & b){
		BIGNUM c;
		c.clean();
		int len = max(a.x[0],b.x[0]);
		int tem = 0;
		for (int i = 1; i <= len; i++){
			tem = (a.x[i] + b.x[i] + tem);
			c.x[i] = tem % 10;
			tem /= 10;
		}
		if (tem > 0){
			len ++;
			c.x[len] = tem;
		}
		c.x[0] = len;
		return c;
	}
	friend void readln(BIGNUM & a){
		int len = 0;
		char s[101];
		scanf("%s",s);
		len = strlen(s);
		a.x[0] = len;
		for (int i = 0; i < len; i ++){
			a.x[len - i] = s[i] - 48;
		}
		return;
	}
	friend void writeln(BIGNUM &a){
		for (int i = a.x[0]; i >= 1; i--) printf("%d",a.x[i]);
		puts("");
		return;
	}
}a,b,c;

int main(){
	freopen("add.in","r",stdin);
	freopen("add.out","w",stdout);
	readln(a);
	readln(b);
	c = a + b;
	writeln(c);
	return 0;
}