- 计算器的改良
- 2009-03-07 15:05:22 @
编译通过...
├ 测试数据 01:答案正确... 0ms
├ 测试数据 02:答案正确... 0ms
├ 测试数据 03:答案正确... 0ms
├ 测试数据 04:答案正确... 0ms
├ 测试数据 05:答案错误...
├ 标准行输出 a=0.00...
├ 错误行输出 a=-0.0...
program yiyuan;
var z,l,gs,xz,xy,cz,cy:longint;
s,s1,s2,gz:string;
w:char;
shu,zi:set of 30..120;
procedure chu(var s:string);
var l,i:integer;
begin
if ord(s[1])>64 then s:=concat('+1',s);
if ord(s[1]) in shu then s:=concat('+',s);
i:=pos('=',s);
if ord(s)>64 then insert('+1',s,i+1);
if ord(s)in shu then insert('+',s,i+1);
l:=length(s);
for i:=l downto 1 do
if (ord(s[i])>64) and (ord(s) in zi) then insert('1',s,i);
end;
procedure xx(var s:string; var x:longint);
var b,j,i,z,v:integer;
begin
z:=length(s);
for b:=z downto 1 do
if ord(s)>64 then begin j:=b; i:=b; w:=s;
repeat
dec(i);
until ord(s[i]) in zi;
gz:=copy(s,i,j-i);
val(gz,gs,v);
x:=x+gs; delete(s,i,j-i+1);
end;
end;
procedure shuzi(s:string; var c:longint);
var b,j,i,l,v:integer;
begin
l:=length(s);
for b:=1 to l do
if ord(s) in zi then begin j:=b; i:=b;
repeat
inc(i);
until (ord(s[i]) in zi) or (i=l);
if il then begin
gz:=copy(s,j,i-j); val(gz,gs,v);
end;
if i=l then begin gz:=copy(s,j,i-j+1); val(gz,gs,v); end;
c:=c+gs;
end;
end;
begin
readln(s); shu:=[48..57]; zi:=[43..45]; xz:=0; xy:=0; cz:=0; cy:=0;
chu(s);
l:=length(s);
z:=pos('=',s);
s1:=copy(s,1,z-1);
xx(s1,xz);
shuzi(s1,cz);
l:=length(s);
s2:=copy(s,z+1,l);
l:=length(s2);
xx(s2,xy);
shuzi(s2,cy);
write(w,'=');
write((cy-cz)/(xz-xy):0:3);
end.
1 条评论
-
lz9506 LV 8 @ 2009-06-15 19:56:06
像你这样如果是
-3x=0就完了!!!
- 1