var
  I1,I2,I3,I4,I5,I6,I7,I8: Integer;
  a:Array[1..4] Of PChar;// = '+-*/';    //('+','-','*','/');
  s1:string;
begin
  mmo1.Lines.Clear;
  a[1]:='+';
  a[2]:='-';
  a[3]:='*';
  a[4]:='/';
  for I1 := 1 to 4 do
    for I2 := 1 to 4 do
      for I3 := 1 to 4 do
        for I4 := 1 to 4 do
          for I5 := 1 to 4 do
            for I6 := 1 to 4 do
              for I7 := 1 to 4 do
                for I8 := 1 to 4 do begin
                   s1:='1'+a[I1]+'2'+a[I2]+'3'+a[I3]+'4'+a[I4]+'5'+a[I5]+'6'+a[I6]+'7'+a[I7]+'8'+a[I8]+'9';
                   bcParser1.expression:=s1;
                   if bcParser1.Value=100 then
                     mmo1.lines.add(s1+'=100');
                end;
end;

解决方案 »

  1.   

    楼上充分利用bcParser,好办法。
      

  2.   

    a:Array[1..4] Of PChar  怎么在定义的时候赋值?a:Array[1..4] Of PChar=(’+‘,’-‘,’*‘,’/’)居然不行谢谢
      

  3.   

    const
      a: Array [1 .. 4] Of PChar = ('+', '-', '*', '/');
      

  4.   

    [dcc32 Error] SDIMAIN.PAS(92): E2195 Cannot initialize local variables我也是楼上这样做的,可就是报错
      

  5.   

    准确说:如果const
      a: Array [1 .. 4] Of PChar = ('+', '-', '*', '/');
    就无法在程序运行中再改变数组的 内容如果  var 
     a: Array [1 .. 4] Of PChar = ('+', '-', '*', '/');
    就会报楼上的错误有没有两全其美的办法,谢谢
      

  6.   

    不使用bcParser,完全通过模仿人工计算代码如下:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I,II,I1,I2,I3,I4,I5,I6,I7,I8: Integer;
      a:Array[1..4] Of PChar;
      B:Array [1..9] of Double;
      s1:string;begin
      memo1.Lines.Clear;
      a[1]:='+';
      a[2]:='-';
      a[3]:='*';
      a[4]:='/';
      for I8 := 1 to 4 do
        for I7 := 1 to 4 do
          for I6 := 1 to 4 do
            for I5 := 1 to 4 do
              for I4 := 1 to 4 do
                for I3 := 1 to 4 do
                  for I2 := 1 to 4 do
                    for I1 := 1 to 4 do
                    begin
                      B[1]:=1;
                      B[2]:=2;
                      B[3]:=3;
                      B[4]:=4;
                      B[5]:=5;
                      B[6]:=6;
                      B[7]:=7;
                      B[8]:=8;
                      B[9]:=9;
                      if B[9]<>0 then
                      if i8=4 then begin
                                     B[8]:= B[8]/B[9];
                                     B[9]:=0;
                                   end;
                      if i8=3 then begin
                                     B[8]:= B[8]*B[9];
                                     B[9]:=0;
                                   end;
                      if B[8]<>0 then
                      if i7=4 then begin
                                     B[7]:= B[7]/B[8];
                                     B[8]:=0;
                                   end;
                      if i7=3 then begin
                                     B[7]:= B[7]*B[8];
                                     B[8]:=0;
                                   end;
                      if B[7]<>0 then
                      if i6=4 then begin
                                     B[6]:= B[6]/B[7];
                                     B[7]:=0;
                                   end;
                      if i6=3 then begin
                                     B[6]:= B[6]*B[7];
                                     B[7]:=0;
                                   end;
                      if B[6]<>0 then
                      if i5=4 then begin
                                     B[5]:= B[5]/B[6];
                                     B[6]:=0;
                                   end;
                      if i5=3 then begin
                                     B[5]:= B[5]*B[6];
                                     B[6]:=0;
                                   end;
                      if B[5]<>0 then
                      if i4=4 then begin
                                     B[4]:= B[4]/B[5];
                                     B[5]:=0;
                                   end;
                      if i4=3 then begin
                                     B[4]:= B[4]*B[5];
                                     B[5]:=0;
                                   end;
                      if B[4]<>0 then
                      if i3=4 then begin
                                     B[3]:= B[3]/B[4];
                                     B[4]:=0;
                                   end;
                      if i3=3 then begin
                                     B[3]:= B[3]*B[4];
                                     B[4]:=0;
                                   end;
                      if B[3]<>0 then
                      if i2=4 then begin
                                     B[2]:= B[2]/B[3];
                                     B[3]:=0;
                                   end;
                      if i2=3 then begin
                                     B[2]:= B[2]*B[3];
                                     B[3]:=0;
                                   end;
                      if B[2]<>0 then
                      if i1=4 then begin
                                     B[1]:= B[1]/B[2];
                                     B[2]:=0;
                                   end;
                      if i1=3 then begin
                                     B[1]:= B[1]*B[2];
                                     B[2]:=0;
                                   end;
                      if i8=2 then begin
                                     B[8]:= B[8]-B[9];
                                     B[9]:=0;
                                   end;
                      if i8=1 then begin
                                     B[8]:= B[8]+B[9];
                                     B[9]:=0;
                                   end;
                      if i7=2 then begin
                                     B[7]:= B[7]-B[8];
                                     B[8]:=0;
                                   end;
                      if i7=1 then begin
                                     B[7]:= B[7]+B[8];
                                     B[8]:=0;
                                   end;
                      if i6=2 then begin
                                     B[6]:= B[6]-B[7];
                                     B[7]:=0;
                                   end;
                      if i6=1 then begin
                                     B[6]:= B[6]+B[7];
                                     B[7]:=0;
                                   end;
                      if i5=2 then begin
                                     B[5]:= B[5]-B[6];
                                     B[6]:=0;
                                   end;
                      if i5=1 then begin
                                     B[5]:= B[5]+B[6];
                                     B[6]:=0;
                                   end;
                      if i4=2 then begin
                                     B[4]:= B[4]-B[5];
                                     B[5]:=0;
                                   end;
                      if i4=1 then begin
                                     B[4]:= B[4]+B[5];
                                     B[5]:=0;
                                   end;
                      if i3=2 then begin
                                     B[3]:= B[3]-B[4];
                                     B[4]:=0;
                                   end;
                      if i3=1 then begin
                                     B[3]:= B[3]+B[4];
                                     B[4]:=0;
                                   end;
                      if i2=2 then begin
                                     B[2]:= B[2]-B[3];
                                     B[3]:=0;
                                   end;
                      if i2=1 then begin
                                     B[2]:= B[2]+B[3];
                                     B[3]:=0;
                                   end;
                      if i1=2 then begin
                                     B[1]:= B[1]-B[2];
                                     B[2]:=0;
                                   end;
                      if i1=1 then begin
                                     B[1]:= B[1]+B[2];
                                     B[2]:=0;
                                   end;
                      B[1]:=B[1]+B[2]+B[3]+B[4]+B[5]+B[6]+B[7]+B[8]+B[9];
                      s1:='1'+a[I1]+'2'+a[I2]+'3'+a[I3]+'4'+a[I4]+'5'+a[I5]+'6'+a[I6]+'7'+a[I7]+'8'+a[I8]+'9';
                      if (B[1]>99.9999) and (B[1]<100.0001) then
                      begin
                        memo1.lines.add(s1+'=100');
                      end;
                    end;
    end;
      

  7.   

    楼上的 不满足 先乘除 后加减吧。这样的赋值方式 真的 delphi就不支持:var    a:Array[1..4] Of PChar;
    begin    a:='+-*/';请指教