比赛 防止浮躁的小练习v0.4 评测结果 AAAAAA
题目名称 增强的减法问题 最终得分 100
用户昵称 Zwoi_Lpat 运行时间 0.000 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2016-10-13 16:57:44
显示代码纯文本
program maxinyang;
var a,b:array[0..101] of integer;
c,d:string;
e,f,g,h,i,j,k,l,m,n,o:integer;
begin

assign(input,'sub.in');
assign(output,'sub.out');
reset(input);
rewrite(output);

readln(c);
readln(d);
e:=length(c);
f:=length(d);
for j:=0 to 101 do
begin
a[j]:=0;
b[j]:=0;
end;
for g:=e downto 1 do
a[e-g]:=ord(c[g])-ord('0');
for h:=f downto 1 do
b[f-h]:=ord(d[h])-ord('0');
if e<f then e:=f;
if a[e-1]>b[e-1] then
begin
for i:=0 to e do
begin
a[i]:=a[i]-b[i];
if a[i]<0 then
begin
a[i]:=a[i]+10;
a[i+1]:=a[i+1]-1;
end;
end;
l:=101;
while a[l]=0 do l:=l-1;
for m:=l downto 0 do
write(a[m]);
end
else
begin
o:=e-1;
while o>=0 do
begin
if a[o]<b[o] then
begin
for i:=0 to e do
begin
b[i]:=b[i]-a[i];
if b[i]<0 then
begin
b[i]:=b[i]+10;
b[i+1]:=b[i+1]-1;
end;
end;
l:=101;
while b[l]=0 do l:=l-1;
write('-');
for m:=l downto 0 do
write(b[m]);
o:=-1;
end;
if a[o]>b[o] then
begin
for i:=0 to e do
begin
a[i]:=a[i]-b[i];
if a[i]<0 then
begin
a[i]:=a[i]+10;
a[i+1]:=a[i+1]-1;
end;
end;
l:=101;
while a[l]=0 do l:=l-1;
for m:=l downto 0 do
write(a[m]);
o:=-1;
end;
if a[o]=b[o] then o:=o-1;
if o=0 then writeln('0');
end;
end;

close(input);
close(output);

end.