请用+-*/()这几种运算规则完成下面一个等式
 3  3   8  8=24
等式前面的数字可以交换位置,运算符可以重复使用但是数字不能重复使用
要求用编程的方法实现!!!(答案已经有了,关键是编程实现的过程!)

解决方案 »

  1.   

    --csdn的FAQ:
    VAR
      card:array[1..4] of integer;
      i,j,k,l,o,p,q,r:integer;
      conti:char;Function right(q:real):boolean;Begin
      if ((q-24)<0.0001)and((24-q)<0.0001) then right:=true
              else right:=false;
    End;
    Function try(x,m,y:real):real;Begin
      if m=1 then try:=x+y;
      if m=2 then try:=x-y;
      if m=3 then try:=x*y;
      if (m=4)and(y<>0) then try:=x/y;
    End;Function ch(s:integer):char;Begin
      case s of
        1:ch:='+';
        2:ch:='-';
        3:ch:='*';
        4:ch:='/';
      end;
    End;Procedure answer(i,j,k,l,o,p,q,t:integer);Begin
      if r mod 4 =0 then writeln;
      if t=1 then write('((',card[i],ch(o),card[j],')',ch(p),card[k],')',ch(q),card[l],'    ')
        else  write('(',card[i],ch(o),card[j],')',ch(p),'(',card[k],ch(q),card[l],')    ');
    End;Procedure new;Var
      i:integer;Begin
      for i:=1 to 4 do
        card[i]:=random(13)+1;
      writeln;
      for i:=1 to 4 do
        if card[i]=11 then write('J     ')
          else if card[i]=12 then write('Q     ')
            else if card[i]=13 then write('K     ')
              else if card[i]=1 then write('A     ')
                else write(card[i],'     ');
      End;Procedure showresult;Begin
      for i:=1 to 4 do
        for j:=1 to 4 do
          for k:=1 to 4 do
            for l:=1 to 4 do
              if (i<>j)and(i<>k)and(i<>l)and(j<>k)and(j<>l)and(k<>l) then
                for o:=1 to 4 do
                  for p:=1 to 4 do
                    for q:=1 to 4 do
                      if right(try(try(try(card[i],o,card[j]),p,card[k]),q,card[l])) then
                      begin
                        answer(i,j,k,l,o,p,q,1);
                        r:=r+1;
                      end
                        else if right(try(try(card[i],o,card[j]),p,try(card[k],q,card[l]))) then
                      begin
                        answer(i,j,k,l,o,p,q,2);
                        r:=r+1;
                      end;
      writeln;
      if r=0 then writeln('Sorry,there is no answer!')
        else if r<>1 then writeln('There are ',r,' answears!')
          else writeln('There is only one answer!');
    End;BEGIN
      randomize;
      clrscr;
      write('24 Points Ver 0.1');  repeat
        new;
        r:=0;
        readln;
        showresult;
        write('Try once more?(y/n)');
        readln(conti);
      until (conti='n')or(conti='N');  writeln;
      writeln('Thanks for using it! Made By Gilbert 2K.12.2');END.
      

  2.   

    try的函数名要改一下,clrscr去掉,似乎pascal没这个语法