比赛 普及组2016模拟练习4 评测结果 AAAAAAAAAA
题目名称 火星上的加法运算 最终得分 100
用户昵称 forewing 运行时间 0.001 s
代码语言 Pascal 内存使用 0.16 MiB
提交时间 2016-11-17 20:12:20
显示代码纯文本
program madition;
const
	name='madition';
var
	a1,a2,ans:array[0..1000] of longint;
	n,i,j,l1,l2,ll:longint;
	r1,r2:string;
function max(l,r:longint):longint;
	begin
		if l>r
		then
			exit(l)
		else
			exit(r);
	end;
function chrtonum(c:char):longint;
	begin
		if ord(c)<=57
		then	
			exit(ord(c)-48)
		else
			exit(ord(c)-87);
	end;
function numtochr(num:longint):char;
	begin
		if num<=9
		then
			exit(chr(num+48))
		else
			exit(chr(num+87));
	end;
begin
	assign(input,name+'.in');
	reset(input);
	assign(output,name+'.out');
	rewrite(output);
	readln(n);
	readln(r1);
	readln(r2);
	l1:=length(r1);
	l2:=length(r2);
	ll:=max(l1,l2);
	for i:=1 to l1 do
		a1[i]:=chrtonum(r1[l1-i+1]);
	for i:=1 to l2 do
		a2[i]:=chrtonum(r2[l2-i+1]);
	for i:=1 to ll do
		ans[i]:=a1[i]+a2[i];
	for i:=1 to ll do
	begin
		ans[i+1]:=ans[i+1]+(ans[i] div n);
		ans[i]:=ans[i] mod n;
	end;
	if ans[ll+1]<>0
	then
		inc(ll);
	for i:=ll downto 1 do
		write(numtochr(ans[i]));
	close(output);
end.