记录编号 |
113557 |
评测结果 |
AAAAAAAAAA |
题目名称 |
增强的除法问题 |
最终得分 |
100 |
用户昵称 |
传奇 |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.003 s |
提交时间 |
2014-07-24 15:34:14 |
内存使用 |
0.17 MiB |
显示代码纯文本
program cojs1066;
type
atype=array[0..300]of longint;
var
s1,s2:string;
yop,i,j,k,m,n:longint;
a,b,c:atype;
ans:atype;
function da(a,b:atype):boolean;
var
i:longint;
begin
if a[0]>b[0] then exit(true);
if a[0]<b[0] then exit(false);
for i:=a[0] downto 1 do
if a[i]>b[i] then
exit(true)
else if a[i]<b[i] then
exit(false);
exit(true);
end;
procedure jian(var a,b:atype);
var
i,k:longint;
begin
for i:=1 to a[0] do
a[i]:=a[i]-b[i];
for i:=1 to a[0]-1 do
if a[i]<0 then
begin
a[i]:=a[i]+10;
dec(a[i+1]);
end;
while (a[a[0]]=0)and(a[0]<>1) do
dec(a[0]);
end;
procedure yi(var a:atype);
var
i:longint;
begin
for i:=a[0] downto 1 do
a[i+1]:=a[i];
a[1]:=0;
if a[a[0]+1]<>0 then
inc(a[0]);
end;
begin
assign(input,'div.in');
assign(output,'div.out');
reset(input);
rewrite(output);
readln(s1);
readln(s2);
n:=length(s1);
m:=length(s2);
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
fillchar(c,sizeof(c),0);
fillchar(ans,sizeof(ans),0);
if ((n=m)and(s1<s2))or(n<m) then
begin
writeln(0);
close(input);
close(output);
halt;
end;
for i:=1 to n do
a[i]:=ord(s1[n-i+1])-ord('0');
for i:=1 to m do
b[i]:=ord(s2[m-i+1])-ord('0');
for i:=n downto n-m+2 do
c[i-n+m-1]:=a[i];
c[0]:=m-1; b[0]:=m; a[0]:=n;
for i:=n-m+1 downto 1 do
begin
yi(c);
c[1]:=a[i];
if (c[1]<>0)and(c[0]=0) then inc(c[0]);
while da(c,b) do
begin
inc(ans[i]);
jian(c,b);
end;
end;
ans[0]:=n-m+1;
while (ans[ans[0]]=0)and(ans[0]<>1) do
dec(ans[0]);
for i:=ans[0] downto 1 do
write(ans[i]);
writeln;
close(input);
close(output);
end.