比赛 NOIP2015普及组练习 评测结果 AAAAAA
题目名称 增强的减法问题 最终得分 100
用户昵称 萌萌哒姐姐 运行时间 0.002 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2015-11-06 08:57:54
显示代码纯文本
const max=255;
var
  a,b,c:array[1..max] of integer;
  n,n1,n2:string;
  lena,lenb,lenc,i:integer;
begin
	assign(input,'sub.in');reset(input);
	assign(output,'sub.out');rewrite(output);
  readln(n1);
  readln(n2);
  if(length(n1)<length(n2)) or (length(n1)=length(n2)) and (n1 < n2) then
  begin
    n:=n1; n1:=n2; n2:=n;
    write('-');
  end;
  lena:=length(n1); lenb:=length(n2);
  for i:=1 to lena do a[lena-i+1]:=ord(n1[i])-ord('0');
  for i:=1 to lenb do b[lenb-i+1]:=ord(n2[i])-ord('0');
  i:=1;
  while i<=lena do
  begin
    if a[i]<b[i] then
    begin
      a[i]:=a[i]+10;
      a[i+1]:=a[i+1]-1;
    end;
    c[i]:=a[i]-b[i];
    i:=i+1;
  end;
  lenc:=i;
  while(c[lenc]=0) and (lenc>1) do dec(lenc);
  for i:=lenc downto 1 do write(c[i]);
  close(input);close(output);
end.