sorry,忘记了告诉大家,1..10之间可以随机重复数字.如可以选4个5.

解决方案 »

  1.   

    float q1,q2,q3,q4;
    float* o(q1,q2)
    { float r1=q1+q2;
    float r2=q1-q2;
    float r3=q1*q2;
    float r4=q1/q2;
    float r[4]={r1,r2,r3,r4}
    return r;
    }
    work()
    { float q1,q2,q3,q4;
    for(q1=1; q1<=10;q1++)
    { for(q2=1; q2<=10;q2++)
    { for(q3=1; q3<=10;q3++)
    { for(q4=1; q4<=10;q4++)
    { float *p=o(o(o(q1,q2),q3),q4);
    for(int i=0; i<3; i++)
    { if(*(p+i)==24)
    {printf("%f,%f,%f,%f",&q1,&q2,&q3,&q4);
    }
    }
    }
    }
    }
    }
    }
      

  2.   

    #include <iostream>
    #include <stdlib.h>
    #include <time.h>using namespace std;bool Result(int x1,int x2,int x3,int x4)
    {
       return ((((x1 + x2 - x3) * x4) == 24)? true : false);
    }void main()
    {
    srand((unsigned)time( NULL ));
    int x[4];
            for(int i=0; i<sizeof(x)/sizeof(int); i++)
    {
    int y = rand()%11;
    cout<<y<<'\t';;
    x[i] = y<1 ? 1:y;
    }
    if(Result(x[0], x[1], x[2],x[3]))
    {
    cout<<"yes"<<endl;
    }
    else
    {
    cout<<"no"<<endl;
    }

    }
      

  3.   

    http://expert.csdn.net/Expert/topic/2050/2050317.xml?temp=.5616419
    看看这个。
      

  4.   

    #include <iostream>
    #include <stdlib.h>
    #include <time.h>using namespace std;
    int work(char op, int x1,int x2)
    {
    switch(op)
    {
    case '+':
    return x1 + x2;

    case '-':
    return x1 - x2;

    case '*':
    return x1 * x2;

    case '/':
    return x1 / x2;

    default:
    break;
    }
    }bool Result(int para[])
    {
       char sign[4] = {'+','-','*','/'};
       char t[3];
       char sig[6][3];
       
       for(int i=0; i<4; i++)
    {
          for(int j=0; j<3; j++)
    {
    t[j] = sign[(j+i)%4];
    //cout<<t[j]<<" ";

    }

       for(int x=0; x<6; x++)
    {
    int z=x;
    for(int y=0; y<3;y++)
    {
    sig[x][y] = t[z%3];
    x<=2 ? ++z : --z;
    //cout<<sig[x][y];
    }
    }
    for(int a=0; a<6; a++)
        {
      int result = 0;
      for(int b=0; b<3; b++)
    {
    result += work(sig[a][b],para[b],para[b+1]);
    cout<<(char)sig[a][b]<<' ';
    }
    cout<<"r = "<<result<<'\t';
    if(result == 24)
    return true;
        }
    }

    }
    void main()
    {
    srand((unsigned)time( NULL ));
    int x[4];
           for(int i=0; i<sizeof(x)/sizeof(int); i++)
    {
    int y = rand()%11;
    cout<<y<<'\t';;
    x[i] = y<1 ? 1:y;
    } if(Result(x))
    {
    cout<<"yes"<<endl;
    for(int i=0;i<sizeof(x);i++)
    cout<<x[i]<<'\t';
    }
    else
    {
    cout<<"no"<<endl;
    }
    }
      

  5.   

    bool Result(int para[])
    {
       char sign[4] = {'+','-','*','/'};
       char t[3];
       char sig[6][3];
       
       for(int i=0; i<4; i++)
    {
          for(int j=0; j<3; j++)
    {
    t[j] = sign[(j+i)%4];
    //cout<<t[j]<<" ";

    }

       for(int x=0; x<6; x++)
    {
    int z=x;
    for(int y=0; y<3;y++)
    {
    sig[x][y] = t[z%3];
    x<=2 ? ++z : --z;
    //cout<<sig[x][y];
    }
    }
    for(int a=0; a<6; a++)
        {
      int result = 0;
      for(int b=0; b<3; b++)
    {
    result += work(sig[a][b],para[b],para[b+1]);
    cout<<(char)sig[a][b]<<' ';
    }
    cout<<"r = "<<result<<'\t';
    if(result == 24)
    return true;
        }
    }
           
           return false;   //必须加上这句
    }刚才比较仓促,少了一条语句,现加上。
      

  6.   

    用vb可以实现,当然vb.net也可以了。
      

  7.   

    <Script language="JavaScript">
    function getRandom(){
    return parseInt(Math.random()*10)+1;
    }
    function getTempResult(v1,v2,oNum){
    switch(oNum){
    case 0:
    return v1+v2;
    case 1:
    return v1-v2;
    case 2:
    return v1*v2;
    case 3:
    if(v1%v2==0) return v1/v2;
    default:
    break;
    }
    }
    function work(){
    var MyArr=new Array(4);
    for(var i=0;i<4;i++)
    MyArr[i]=getRandom();
    for(var a=0;a<4;a++){
    for(var b=0;b<4;b++){
    if(b!=a){
    for(var c=0;c<4;c++){
    var tempValue1=getTempResult(MyArr[a],MyArr[b],c);
    for(var d=0;d<4;d++){
    if(d!=a&&d!=b){
    for(var e=0;e<4;e++){
    var tempValue2=getTempResult(tempValue1,MyArr[d],e);
    for(var f=0;f<4;f++){
    if(f!=a&&f!=b&&f!=d&&tempValue1!=tempValue2){
    for(var g=0;g<4;g++){
    var tempValue=getTempResult(tempValue2,MyArr[f],g);
    if(tempValue==24)
    return true
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    </Script>
      

  8.   

    思想第一,代码其次.
    [推荐]http://www.csdn.net/develop/Read_Article.asp?Id=20719里面的代码是由 csdn数据算法版牛人 胡海星 所写,非常值得一看 :)
      

  9.   

    create table o
    (
    code char(1) not null
    )
    insert into o values('+')
    insert into o values('-')
    insert into o values('*')
    insert into o values('/')
    gocreate table t
    (
    id int not null
    )
    insert into t values(1)
    insert into t values(2)
    insert into t values(3)
    insert into t values(4)
    insert into t values(5)
    insert into t values(6)
    insert into t values(7)
    insert into t values(8)
    insert into t values(9)
    insert into t values(10)
    go--sql解法
    select * 
    from t a, o o1, t b, o o2, t c, o o3, t d 
    where 
    (case o3.code
    when '+' then 
    (case o2.code 
    when '+' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)+c.id
    when '-' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)-c.id
    when '*' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)*c.id
    when '/' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)/c.id
    end)+d.id
    when '-' then 
    (case o2.code
    when '+' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)+c.id
    when '-' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)-c.id
    when '*' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)*c.id
    when '/' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)/c.id
    end)-d.id
    when '*' then 
    (case o2.code
    when '+' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)+c.id
    when '-' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)-c.id
    when '*' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)*c.id
    when '/' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)/c.id
    end)*d.id
    when '/' then 
    (case o2.code
    when '+' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)+c.id
    when '-' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)-c.id
    when '*' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)*c.id
    when '/' then 
    (case o1.code
    when '+' then a.id+b.id
    when '-' then a.id-b.id
    when '*' then a.id*b.id
    when '/' then a.id/b.id
    end)/c.id
    end)/d.id
    end)=24
      

  10.   

    TO: jyk1970() 的结果:
    1.有重复的,如:
    10 + 9 + 1 + 4
    9 + 10 + 1 + 4
    2.有漏掉的,如:
    10/5 * 10 + 4;
    10/5 * 9 + 6;
    9/3 * 5 + 9;
    7*8 / 2 - 4;
    ............
    就是你至少落了*或/与+,与-的组合。
     
      

  11.   

    http://expert.csdn.net/Expert/topic/2735/2735514.xml?temp=.4493677
      

  12.   

    斑竹请帮忙把
    http://expert.csdn.net/Expert/TopicView1.asp?id=2672395
    揭帖了
    谢谢
      

  13.   

    高手们编了不少代码了,我来试着分析一下问题实质吧:<1>数值组合:获取1~10组成的可重复的四个值的任意组合C1;〈2〉符号组合:获取'+','-','*','/'四个符号中可重复的三个值的任意组合C2;<3>排序:对得到的符号集合C2排序 得到符号序列P2;<4>分组:将得到的数值集合C1分组(如:(((a1,a2),a3),a4)和((a1,a2),(a3,a4))为两种不同的分组)得到分组集合Z2;<5>插入:将符号序列P2插入数值分组集合Z2;<5>差错控制:如果在一个数值组合C1[X]中得到了一个预期结果值true,则跳出本集合中的过程(防止出现重复),执行下一集合上的操作;<6>缺省返回值:false。
        呵呵,不知道分析的对不对,请高手们多指教哦~~~,没时间编代码了,下次补上吧~~。