比赛 防止浮躁的小练习v0.4 评测结果 AAAAAA
题目名称 增强的减法问题 最终得分 100
用户昵称 Zwoi_John Price 运行时间 0.000 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2016-10-13 22:00:43
显示代码纯文本
program jianfa;
var
  x,y:array[0..101] of integer;
  s1,s2,s:string;
  l1,l2,l3,i,i1:byte;
begin
  assign(input,'sub.in');
  assign(output,'sub.out');
  reset(input);
  rewrite(output);

  readln(s);
  s1:=s;
  l1:=length(s1);
  for i:=0 to 101 do x[i]:=0;

  for i:=l1 downto 1 do x[i]:=ord(s1[l1-i+1])-48;
  readln(s);
  s2:=s;
  l2:=length(s2);
  for i:=0 to 101 do y[i]:=0;

  for i:=l2 downto 1 do y[i]:=ord(s2[l2-i+1])-48;
  if l1<l2 then l3:=l2
  else l3:=l1;

  if (s1=s2) then writeln(0)
  else if (l1=l2) then
  begin
    if s1>s2 then
    begin
      for i:=1 to l3 do
      begin
        x[i]:=x[i]-y[i];
        if (x[i]<0) then
        begin
          if (x[i+1]=0) then
          begin
            i1:=i+1;
            while (x[i1]=0) and (i1<l1) do
            begin
              x[i1]:=9;
              i1:=i1+1;
            end;
            x[i1]:=x[i1]-1;
          end
          else
          begin
          x[i+1]:=x[i+1]-1;
          end;
          x[i]:=10+x[i];
        end;
      end;
    i1:=101;
    while x[i1]=0 do i1:=i1-1;
    for i:=i1 downto 1 do write(x[i]);
    end
    else if s1<s2 then
    begin
      for i:=1 to l3 do
      begin
        y[i]:=y[i]-x[i];
        if (y[i]<0) then
        begin
          if (y[i+1]=0) then
          begin
            i1:=i+1;
            while (y[i1]=0) and (i1<l2) do
            begin
              y[i1]:=9;
              i1:=i1+1;
            end;
            y[i1]:=y[i1]-1;
          end
          else
          begin
          y[i+1]:=y[i+1]-1;
          end;
          y[i]:=10+y[i];
        end;
      end;
    i1:=101;
    while y[i1]=0 do i1:=i1-1;
    write('-');
    for i:=i1 downto 1 do write(y[i]);
    end;
  end
  else if (l1>l2) then
  begin
    for i:=1 to l3 do
    begin
      x[i]:=x[i]-y[i];
      if (x[i]<0) then
      begin
        if (x[i+1]=0) then
          begin
            i1:=i+1;
            while (x[i1]=0) and (i1<l1) do
            begin
              x[i1]:=9;
              i1:=i1+1;
            end;
            x[i1]:=x[i1]-1;
          end
          else
          begin
          x[i+1]:=x[i+1]-1;
          end;
        x[i]:=10+x[i];
      end;
    end;
    i1:=101;
    while x[i1]=0 do i1:=i1-1;
    for i:=i1 downto 1 do write(x[i]);
  end
  else if (l2>l1) then
  begin
    for i:=1 to l3 do
      begin
        y[i]:=y[i]-x[i];
        if (y[i]<0) then
        begin
          if (y[i+1]=0) then
          begin
            i1:=i+1;
            while (y[i1]=0) and (i1<l2) do
            begin
              y[i1]:=9;
              i1:=i1+1;
            end;
            y[i1]:=y[i1]-1;
          end
          else
          begin
            y[i+1]:=y[i+1]-1;
          end;
          y[i]:=10+y[i];
        end;
      end;
    i1:=101;
    while y[i1]=0 do i1:=i1-1;
    write('-');
    for i:=i1 downto 1 do write(y[i]);
  end;
  readln;

  close(input);
  close(output);
end.