主题:[原创]PASCAL漏洞????????
绝对让你大吃一惊,一个PASCAL程序连续运行,对同样的输入竟有不同的答案输出,天啊,那我岂不是白写了这程序,紧急求助----------
(一下这个程序按上面所说运行一下)!!!!!!!!!
program canlator;
type ty=array[0..100]of integer;
var i,j:integer;
sm,sn:string;m,n:ty;
PROCEDURE xuzheng(var a:ty);
var i:integer;
begin
while (a[a[0]]=0)and(a[0]>1)do
a[0]:=a[0]-1;
end;
PROCEDURE add(var a,b:ty);
var l:ty;i,p:integer;
begin
if a[0]>b[0] then begin
for i:=1 to a[0] do
l[i]:=a[i];
l[0]:=a[0]+1;
for i:=1 to b[0] do
begin
p:=l[i]+b[i];
l[i]:=p mod 10;
l[i+1]:=l[i+1]+p div 10;
end;
end
else begin
for i:=1 to b[0] do
l[i]:=b[i];
l[0]:=b[0]+1;
for i:=1 to a[0] do
begin
p:=l[i]+a[i];
l[i]:=p mod 10;
l[i+1]:=l[i+1]+p div 10;
end;
xuzheng(l);a[0]:=l[0];
for i:=1 to l[0] do
a[i]:=l[i];
end;
end;
procedure mul(var a:ty;x:integer);
var p,i:integer;
begin
p:=0;
for i:=1 to a[0] do
begin
inc(p,a[i]*x);
if p>10 then a[i]:=p mod 10 else a[i]:=p;
p:=p div 10;
end;
while p>0 do
begin
inc(a[0]);
if p>10 then a[a[0]]:=p mod 10 else a[a[0]]:=p;
p:=p div 10;
end;
xuzheng(a);
end;
procedure chen(var a,b:ty);
var l,t:ty;i,j:integer;
begin
for i:=1 to a[0] do l[i]:=0;l[0]:=a[0];
for i:=1 to b[0] do
begin
for j:=1 to a[0] do
t[j]:=a[j];
t[0]:=a[0];
mul(t,b[i]);
for j:=t[0]+i-1 downto 1+i-1 do
t[j]:=t[j-i+1];
for j:=1 to i-1 do
t[j]:=0;
t[0]:=t[0]+i-1;
add(l,t);
for j:=1 to l[0] do
a[j]:=l[j];a[0]:=l[0];
end;
end;
begin
writeln('m,n');
readln(sm);
readln(sn);
for i:=1 to length(sm) do
m[length(sm)-i+1]:=ord(sm[i])-ord('0');
m[0]:=length(sm);
for i:=1 to length(sn) do
n[length(sn)-i+1]:=ord(sn[i])-ord('0');
n[0]:=length(sn);
chen(m,n);
for i:=m[0] downto 1 do
write(m[i]);
end.[em10][em10][em10][em10][em10]
(一下这个程序按上面所说运行一下)!!!!!!!!!
program canlator;
type ty=array[0..100]of integer;
var i,j:integer;
sm,sn:string;m,n:ty;
PROCEDURE xuzheng(var a:ty);
var i:integer;
begin
while (a[a[0]]=0)and(a[0]>1)do
a[0]:=a[0]-1;
end;
PROCEDURE add(var a,b:ty);
var l:ty;i,p:integer;
begin
if a[0]>b[0] then begin
for i:=1 to a[0] do
l[i]:=a[i];
l[0]:=a[0]+1;
for i:=1 to b[0] do
begin
p:=l[i]+b[i];
l[i]:=p mod 10;
l[i+1]:=l[i+1]+p div 10;
end;
end
else begin
for i:=1 to b[0] do
l[i]:=b[i];
l[0]:=b[0]+1;
for i:=1 to a[0] do
begin
p:=l[i]+a[i];
l[i]:=p mod 10;
l[i+1]:=l[i+1]+p div 10;
end;
xuzheng(l);a[0]:=l[0];
for i:=1 to l[0] do
a[i]:=l[i];
end;
end;
procedure mul(var a:ty;x:integer);
var p,i:integer;
begin
p:=0;
for i:=1 to a[0] do
begin
inc(p,a[i]*x);
if p>10 then a[i]:=p mod 10 else a[i]:=p;
p:=p div 10;
end;
while p>0 do
begin
inc(a[0]);
if p>10 then a[a[0]]:=p mod 10 else a[a[0]]:=p;
p:=p div 10;
end;
xuzheng(a);
end;
procedure chen(var a,b:ty);
var l,t:ty;i,j:integer;
begin
for i:=1 to a[0] do l[i]:=0;l[0]:=a[0];
for i:=1 to b[0] do
begin
for j:=1 to a[0] do
t[j]:=a[j];
t[0]:=a[0];
mul(t,b[i]);
for j:=t[0]+i-1 downto 1+i-1 do
t[j]:=t[j-i+1];
for j:=1 to i-1 do
t[j]:=0;
t[0]:=t[0]+i-1;
add(l,t);
for j:=1 to l[0] do
a[j]:=l[j];a[0]:=l[0];
end;
end;
begin
writeln('m,n');
readln(sm);
readln(sn);
for i:=1 to length(sm) do
m[length(sm)-i+1]:=ord(sm[i])-ord('0');
m[0]:=length(sm);
for i:=1 to length(sn) do
n[length(sn)-i+1]:=ord(sn[i])-ord('0');
n[0]:=length(sn);
chen(m,n);
for i:=m[0] downto 1 do
write(m[i]);
end.[em10][em10][em10][em10][em10]