您的位置:首页 > 其它

noip2000-计算器的改良 2008.11.5

2016-02-05 13:11 232 查看
noip2000-计算器的改良 2008.11.5

发现了一个很神奇的bug

write(0/-1) 的结果是-0,前面居然有个负号,这是一个漏洞,注意啊!坑人!

program computer;
const fin='computer.in';fout='computer.out';
var m,x,y,i,j,lx1,lx2:longint;
xx,x1,x2:string;
f1,f2:text;
h:char;
procedure deal(g:string;p1,p2:longint);
var l,f,code,d:longint;t,c:string;
begin l:=length(g);t:='';c:='+';
i:=0;
for i:=1 to l do
begin
if (g[i]>='0') and (g[i]<='9') then t:=t+g[i];
if (g[i]='-') or (g[i]='+') then
begin
case g[i-1]of
'0'..'9':
begin
val(t,f,code);
if c='-' then d:=-1 else d:=1;
y:=y+f*p2*d;t:='';
end;
'a'..'z':
begin  val(t,f,code);if t='' then f:=1;
if c='-' then d:=-1 else d:=1;
x:=x+p1*f*d;
t:='';h:=g[i-1];
end;
end;{case}
c:=g[i];
end;
end;
end;
procedure doit;
begin
assign(f1,fin);reset(f1);
assign(f2,fout);rewrite(f2);
read(f1,xx);
m:=pos('=',xx);
x1:=copy(xx,1,m-1);
x2:=copy(xx,m+1,length(xx)-m);
x1:=x1+'+';
x2:=x2+'+';
deal(x1,1,-1);
deal(x2,-1,1);
if y=0 then writeln(f2,h,'=','0.000')
else  writeln(f2,h,'=',y/x:0:3);
close(f1);close(f2);
end;
begin
doit;
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: