codevs1015

来源:互联网 发布:水果店管理系统源码 编辑:程序博客网 时间:2024/06/11 01:23

题目地址:http://codevs.cn/problem/1015/

分析:

模拟

代码:

var
  i,j,k,n,x,y,max,min:longint;
  a,b,c,d,e:longint;
  ch,ch1,ch2:char;
  s,s1,s2:string;

procedure jjj(ss:string;Var x,y:longint;VAR ch:char);
var
  z,i:longint;
  c,fu:char;
  zimu:boolean;
begin
  x:=0;
  y:=0;
  z:=0;
  fu:='+';
  zimu:=false;
  for i:=1 to length(ss) do
    begin
       c:=ss[i];

       case c of
         '0'..'9':begin

             z:=z*10+ord(c)-48;
                  end;
         'a'..'z':begin
                    zimu:=true;
                    ch:=c;
                  end;
         '+','-': begin
                    if zimu then
                       begin
                         if fu='+' then x:=x+z else x:=x-z;
                       end
                    else
                       begin
                          if fu='+' then y:=y+z else y:=y-z;

                       end;
                    z:=0;
                    fu:=c;
                    zimu:=false;
                  end;


       end;

       if i=length(ss) then
         begin
             if zimu then
                begin
                  if fu='+' then x:=x+z else x:=x-z;
                end
             else
                begin
                  if fu='+' then y:=y+z else y:=y-z;
                end;
         end;
    end;
end;


begin
   readln(s);
   i:=pos('=',s);          //找到等号位置
   s1:=copy(s,1,i-1);     
   s2:=copy(s,i+1,length(s)-i);
   jjj(s1,a,b,ch1);         //计算左边的X项系数,常数项
   jjj(s2,c,d,ch2);         //计算右边的X项系数,常数基
   writeln(ch1,'=',(d-b)/(a-c):0:3);   //解 AX+B=CX+D
end.

0 0
原创粉丝点击