比赛 20101105 评测结果 AAAAAAAAAA
题目名称 火星上的加法运算 最终得分 100
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-05 19:35:18
显示代码纯文本
program madition;
var
	c,c1,c2,code,i,j,n:integer;
	s1,s2:string;
	sum,a,b:array [1..200] of integer;
begin
	assign (input,'madition.in');
	reset (input);
	readln (n);
	readln (s1);
	readln (s2);
	close (input);
	assign (output,'madition.out');
	rewrite (output);
	for i:=length(s1) downto 1 do begin
		j:=length(s1)-i+1;
		if s1[i] in ['0'..'9'] then val(s1[i],a[j],code) else a[j]:=ord(s1[i])-87;
	end;
	c1:=length(s1);
	for i:=length(s2) downto 1 do begin
		j:=length(s2)-i+1;
		if s2[i] in ['0'..'9'] then val(s2[i],b[j],code) else b[j]:=ord(s2[i])-87;
	end;
	c2:=length(s2);
	fillchar (sum,sizeof(sum),0);
	if c1>c2 then c:=c1 else c:=c2;
	for i:=1 to c do begin
                sum[i]:=sum[i]+a[i]+b[i];
		if sum[i]>=n then begin
                        sum[i]:=sum[i]-n;
                        sum[i+1]:=1;
                end;

	end;
	if sum[c+1]<>0 then c:=c+1;
	for i:=c downto 1 do if sum[i]>=10 then write (chr(sum[i]+87)) else write (sum[i]);
	writeln;
	close (output);
end.