记得好像是有一个符号堆栈,还有一个数字堆栈,具体的还要请教高手了.

解决方案 »

  1.   

    给你一个算24的程序:
    function get24(a, b, c, d: integer): integer;
    var
        i, j, k: integer;
        fh: array[1..4] of string;
    begin
        fh[1] := '+';
        fh[2] := '-';
        fh[3] := '*';
        fh[4] := '/';    for i := 1 to 4 do
            for j := 1 to 4 do
                for k := 1 to 4 do
                begin
                    // showmessage(floattostr(calval(k, calval(i, a,calval(j, b, c) ), d)-0.000001));
                    if round(calval(k, calval(i, a, calval(j, b, c)), d)) = 24 then //cal (a+(b+c))+d
                    begin
                        writeln(ff, '(' + inttostr(a) + fh[i] + '(' + inttostr(b) + fh[j] + inttostr(c) + '))' + fh[k] + inttostr(d) + '=24');
                    end;
                    if round(calval(k, calval(j, calval(i, a, b), c), d)) = 24 then //cal ((a+b)+c)+d
                    begin
                        writeln(ff, '((' + inttostr(a) + fh[i] + inttostr(b) + ')' + fh[j] + inttostr(c) + ')' + fh[k] + inttostr(d) + '=24');
                    end;
                    if round(calval(i, a, calval(j, b, calval(k, c, d)))) = 24 then //cal a+(b+(c+d))
                    begin
                        writeln(ff, inttostr(a) + fh[i] + '(' + inttostr(b) + fh[j] + '(' + inttostr(c) + fh[k] + inttostr(d) + '))' + '=24');
                    end;
                    if round(calval(i, a, calval(k, calval(j, b, c), d))) = 24 then //cal a+((b+c)+d)
                    begin
                        writeln(ff, inttostr(a) + fh[i] + '((' + inttostr(b) + fh[j] + inttostr(c) + ')' + fh[k] + inttostr(d) + ')' + '=24');
                    end;
                    if round(calval(j, calval(i, a, b), calval(k, c, d))) = 24 then //cal (a+b)+(c+d))
                    begin
                        writeln(ff, '(' + inttostr(a) + fh[i] + inttostr(b) + ')' + fh[j] + '(' + inttostr(c) + fh[k] + inttostr(d) + ')' + '=24');
                    end;
                end;
    end;
      

  2.   

    这个啊,找本数据结构的基础书籍看看~~~先转逆波兰式google搜索下~~~http://content.edu.tw/senior/computer/ks_ks/et/datastruct/compute/compute.htm
    http://tzsvc.xiloo.com/ks/datastru/dh3.htm找到了一个例子
    http://www.tommstudio.com/zips/tomm/calculator.rar
      

  3.   

    TO:ehom(?!) 
    THANK YOU@! 
    大哥,能不能帮小弟再解决一个问题,嘻嘻.
    http://expert.csdn.net/Expert/topic/1825/1825197.xml?temp=.2016565