比赛 20101105 评测结果 AAAAAAAAAA
题目名称 火星上的加法运算 最终得分 100
用户昵称 王者自由 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-05 19:28:02
显示代码纯文本
program madition;
var x,y,z,i,k:word;
  a,b,c:array[0..250]of byte;
  s:string; u:char;
  list:array[0..35]of char;
  number:array['0'..'z']of byte;
begin
  assign(input,'madition.in'); reset(input);
  assign(output,'madition.out'); rewrite(output);
  for i:=0 to 9 do list[i]:=chr(i+ord('0'));
  for i:=10 to 35 do list[i]:=chr(i-10+ord('a'));
  for u:='0' to '9' do number[u]:=ord(u)-ord('0');
  for u:='a' to 'z' do number[u]:=ord(u)-ord('a')+10;
  
  readln(k);
  readln(s); x:=length(s);
  for i:=1 to x do a[x-i+1]:=number[s[i]];
  readln(s); y:=length(s);
  for i:=1 to y do b[y-i+1]:=number[s[i]];
  fillchar(c,sizeof(c),0); z:=1;
  
  if x>y then z:=x else z:= y;
  for i:=1 to x do inc(c[i],a[i]);
  for i:=1 to y do inc(c[i],b[i]);
  for i:=1 to z do
  begin
    inc(c[i+1],c[i] div k);
    c[i]:=c[i] mod k;
  end;
  while c[z+1]>0 do
  begin
    inc(z);
    inc(c[z+1],c[z] div k);
    c[c[0]]:=c[z] mod k;
  end;
  
  for i:=z downto 1 do write(list[c[i]]);
  writeln;
  close(input); close(output);
end.