算24点吧 关注:18贴子:392
  • 10回复贴,共1

C++程序算24点的

只看楼主收藏回复

输入四位整数,可以输出用四则运算的结果。(仅限+,-,*,/,括号)。
#include <iostream>
#include <cmath> using namespace std;
double ans2(char* c)
{
double a,b;
double sum;
char t;
a=c[2]-48;b=c[4]-48;
t=c[3];
// cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
if(t=='+')
{sum=a+b;}
if(t=='-')
{sum=a-b;}
if(t=='*')
{sum=a*b;}
if(t=='/')
{sum=a/b;}
//cout<<sum<<endl; a=sum;b=c[7]-48;
t=c[6];
// cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
if(t=='+')
{sum=a+b;}
if(t=='-')
{sum=a-b;}
if(t=='*')
{sum=a*b;}
if(t=='/')
{sum=a/b;} a=sum;b=c[10]-48;
t=c[9];
// cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
if(t=='+')
{sum=a+b;}
if(t=='-')
{sum=a-b;}
if(t=='*')
{sum=a*b;}
if(t=='/')
{sum=a/b;} return sum; } void fkind(char* a,int n,int i,char* t,char *p)
{
static int tot=0;
if(i==n)
{
for(int j=0;j<n;j++)
{
// cout<<t[j]<<" ";
p[tot++]=t[j];
}
// cout<<endl;
// cout<<endl<<tot++<<endl;
}
else if(i<n)
{
for(int j=0;j<4;j++)
{
t[i]=a[j];
fkind(a,n,i+1,t,p);
}
}
} void nkind(int* a,int n,int i,int* t,int *p)
{
static int tot=0;
if(i==n)
{
for(int j=0;j<n;j++)
{
// cout<<t[j]<<" ";
p[tot++]=t[j];
}
// cout<<endl;
// cout<<endl<<tot++<<endl;
}
else if(i<n)
{
for(int j=0;j<4;j++)
{
if(a[j]!=-1)
{
t[i]=a[j];
int s=a[j];
a[j]=-1;
nkind(a,n,i+1,t,p);
a[j]=s;
}
}
}
} void equation(int* a,char* b,char* c)
{
c[0]=c[1]='(';
c[5]=c[8]=')';
c[2]=a[0]+48;
c[4]=a[1]+48;
c[7]=a[2]+48;
c[10]=a[3]+48;
c[3]=b[0];
c[6]=b[1];
c[9]=b[2];
c[11]='\0';
} int main()
{
// char c[15];
int a[4];
int num[24][4];
int tn[4];
int* pn=num[0]; char str[64][3];
char cs[4]={'+','-','*','/'};
char tc[4];
char* ps=str[0]; fkind(cs,3,0,tc,ps); for(int i=0;i<4;i++)
cin>>a[i]; nkind(a,4,0,tn,pn); int i,j;
int ok=0;
int tot=0;
for(i=0;i<24;i++)
{
for(j=0;j<64;j++)
{
tot++;
double x=0.0;
char c[15];
equation(num[i],str[j],c);
x=ans2(c);
if(fabs(x-24.0)<=1e-5)
{
ok=1;
for(int k=0;k<11;k++)
cout<<c[k];
cout<<"=24"<<endl;
}
}
if(ok==1)
break;
if(tot==1536)
cout<<"NO ANSWER!\n";
}
return 0;
}


1楼2013-02-18 00:10回复
    运行效果:

    纯手工编写,有BUG可以联系我。


    2楼2013-02-18 00:15
    回复
      好像10位以上的数和负数不能正常显示。。。但结果是对的。只要你能猜出来乱码是什么的话。比如“:”代表“10”。


      3楼2013-02-18 00:23
      回复

        //该进好的
        #include <iostream>
        #include <cmath>
        using namespace std; double ans2(char* c)
        {
        double a,b;
        double sum;
        char t;
        a=c[2]-48;b=c[4]-48;
        t=c[3];
        // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
        if(t=='+')
        {sum=a+b;}
        if(t=='-')
        {sum=a-b;}
        if(t=='*')
        {sum=a*b;}
        if(t=='/')
        {sum=a/b;}
        //cout<<sum<<endl;
        a=sum;b=c[7]-48;
        t=c[6];
        // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
        if(t=='+')
        {sum=a+b;}
        if(t=='-')
        {sum=a-b;}
        if(t=='*')
        {sum=a*b;}
        if(t=='/')
        {sum=a/b;}
        a=sum;b=c[10]-48;
        t=c[9];
        // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
        if(t=='+')
        {sum=a+b;}
        if(t=='-')
        {sum=a-b;}
        if(t=='*')
        {sum=a*b;}
        if(t=='/')
        {sum=a/b;}
        return sum;
        }
        double ans3(char* c)
        {
        char t;
        double a,b;
        double sum1=0,sum2=0,sum=0; a=c[1]-48; b=c[3]-48; t=c[2]; if(t=='+')
        {sum1=a+b;}
        if(t=='-')
        {sum1=a-b;}
        if(t=='*')
        {sum1=a*b;}
        if(t=='/')
        {sum1=a/b;} a=c[7]-48; b=c[9]-48; t=c[8]; if(t=='+')
        {sum2=a+b;}
        if(t=='-')
        {sum2=a-b;}
        if(t=='*')
        {sum2=a*b;}
        if(t=='/')
        {sum2=a/b;} a=sum1; b=sum2; t=c[5]; if(t=='+')
        {sum=a+b;}
        if(t=='-')
        {sum=a-b;}
        if(t=='*')
        {sum=a*b;}
        if(t=='/')
        {sum=a/b;} return sum;
        } void fkind(char* a,int n,int i,char* t,char *p)
        {
        static int tot=0;
        if(i==n)
        {
        for(int j=0;j<n;j++)
        {
        // cout<<t[j]<<" ";
        p[tot++]=t[j];
        }
        // cout<<endl;
        // cout<<endl<<tot++<<endl;
        }
        else if(i<n)
        {
        for(int j=0;j<4;j++)
        {
        t[i]=a[j];
        fkind(a,n,i+1,t,p);
        }
        }
        }
        void nkind(int* a,int n,int i,int* t,int *p)
        {
        static int tot=0;
        if(i==n)
        {
        for(int j=0;j<n;j++)
        {
        // cout<<t[j]<<" ";
        p[tot++]=t[j];
        }
        // cout<<endl;
        // cout<<endl<<tot++<<endl;
        }
        else if(i<n)
        {
        for(int j=0;j<4;j++)
        {
        if(a[j]!=-1)
        {
        t[i]=a[j];
        int s=a[j];
        a[j]=-1;
        nkind(a,n,i+1,t,p);
        a[j]=s;
        }
        }


        4楼2013-02-19 18:37
        回复
          }
          }
          void equation(int* a,char* b,char* c)
          {
          c[0]=c[1]='(';
          c[5]=c[8]=')';
          c[2]=a[0]+48;
          c[4]=a[1]+48;
          c[7]=a[2]+48;
          c[10]=a[3]+48;
          c[3]=b[0];
          c[6]=b[1];
          c[9]=b[2];
          c[11]='\0';
          }
          void equation3(int* a,char* b,char* c)
          {
          c[0]=c[6]='(';
          c[4]=c[10]=')';
          c[1]=a[0]+48;
          c[3]=a[1]+48;
          c[7]=a[2]+48;
          c[9]=a[3]+48;
          c[2]=b[0];
          c[5]=b[1];
          c[8]=b[2];
          c[11]='\0';
          } void actoa2(int* a,char (*p)[5],int *sig)
          {
          int i=0;
          for(i=0;i<4;i++)
          {
          if(sig[i]==1)
          {
          if(*(p+i)[0]=='1') a[i]=1;
          if(*(p+i)[0]=='2') a[i]=2;
          if(*(p+i)[0]=='3') a[i]=3;
          if(*(p+i)[0]=='4') a[i]=4;
          if(*(p+i)[0]=='5') a[i]=5;
          if(*(p+i)[0]=='6') a[i]=6;
          if(*(p+i)[0]=='7') a[i]=7;
          if(*(p+i)[0]=='8') a[i]=8;
          if(*(p+i)[0]=='9') a[i]=9;
          }
          else if(sig[i]==2)
          {
          if(p[i][1]=='0'&&*(p+i)[0]=='1') {a[i]=10; }
          if(p[i][1]=='1'&&*(p+i)[0]=='1') {a[i]=11; }
          if(p[i][1]=='2'&&*(p+i)[0]=='1') {a[i]=12; }
          if(p[i][1]=='3'&&*(p+i)[0]=='1') {a[i]=13; }
          }
          else if(sig[i]==0)
          {
          if(*(p+i)[0]=='a'||*(p+i)[0]=='A') a[i]=1;
          if(*(p+i)[0]=='j'||*(p+i)[0]=='J') a[i]=11;
          if(*(p+i)[0]=='q'||*(p+i)[0]=='Q') a[i]=12;
          if(*(p+i)[0]=='k'||*(p+i)[0]=='K') a[i]=13;
          }
          }
          } int main()
          {
          // char c[15]; int a[4];
          int sig[4];
          char ac[4][5];
          int num[24][4];
          int tn[4];
          int* pn=num[0];
          char str[64][3];
          char cs[4]={'+','-','*','/'};
          char tc[4];
          char* ps=str[0];
          fkind(cs,3,0,tc,ps);
          cout<<"可以输入字母J,Q,K,A代替11,12,13,1:\n";
          for(int i=0;i<4;i++)
          {
          cin>>ac[i];
          if(ac[i][2]=='\0'&&(ac[i][1]=='1'||ac[i][1]=='2'||ac[i][1]=='3'||ac[i][1]=='0')&&ac[i][0]=='1') sig[i]=2;
          else
          {
          if(ac[i][0]>='1'&&ac[i][0]<='9'&&ac[i][1]=='\0') sig[i]=1;
          else sig[i]=0;
          }
          }
          actoa2(a,ac,sig);
          nkind(a,4,0,tn,pn);
          int i,j;
          int ok=0;
          int tot=0;
          for(i=0;i<24;i++)
          {
          for(j=0;j<64;j++)
          {
          tot++;
          double x=0.0;
          char c[15];
          equation(num[i],str[j],c);
          x=ans2(c);
          if(fabs(x-24.0)<=1e-5)
          {
          ok=1;
          for(int k=0;k<11;k++)
          {
          if(k==2||k==4||k==7||k==10)
          {
          if(c[k]==';') c[k]='J';
          else if(c[k]==':') c[k]='T';
          else if(c[k]=='<') c[k]='Q';
          else if(c[k]=='=') c[k]='K';
          else if(c[k]=='1') c[k]='A';
          }
          }
          for(int k=0;k<11;k++)
          cout<<c[k];
          cout<<"=24"<<endl;
          }
          double y=0.0;
          char d[15];
          equation3(num[i],str[j],d);
          y=ans3(d);
          if(fabs(y-24.0)<=1e-5)
          {
          ok=1;
          for(int k=0;k<11;k++)
          {
          if(k==1||k==3||k==7||k==9)
          {
          if(d[k]==';') d[k]='J';
          else if(d[k]==':') d[k]='T';
          else if(d[k]=='<') d[k]='Q';
          else if(d[k]=='=') d[k]='K';
          else if(d[k]=='1') d[k]='A';
          }
          }
          for(int k=0;k<11;k++)
          cout<<d[k];
          cout<<"=24"<<endl;
          } }
          if(ok==1)
          break;
          if(tot==1536)
          cout<<"NO ANSWER!\n";
          }
          char ch;
          cout<<"按任意键结束.....";
          cin>>ch;
          return 0;
          }


          5楼2013-02-19 18:37
          回复
            以下是最新版的,这回不会再出错了:
            *
            为了纪念我24号开学
            */
            #include <iostream>
            #include <cmath>
            using namespace std;double ans2(char* c)
            {
            double a,b;
            double sum;
            char t;
            a=c[2]-48;b=c[4]-48;
            t=c[3];
            // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
            if(t=='+')
            {sum=a+b;}
            if(t=='-')
            {sum=a-b;}
            if(t=='*')
            {sum=a*b;}
            if(t=='/')
            {sum=a/b;}
            //cout<<sum<<endl;
            a=sum;b=c[7]-48;
            t=c[6];
            // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
            if(t=='+')
            {sum=a+b;}
            if(t=='-')
            {sum=a-b;}
            if(t=='*')
            {sum=a*b;}
            if(t=='/')
            {sum=a/b;}
            a=sum;b=c[10]-48;
            t=c[9];
            // cout<<"a: "<<a<<"b: "<<b<<"t: "<<t<<endl;
            if(t=='+')
            {sum=a+b;}
            if(t=='-')
            {sum=a-b;}
            if(t=='*')
            {sum=a*b;}
            if(t=='/')
            {sum=a/b;}
            return sum;
            }
            double ans3(char* c)
            {
            char t;
            double a,b;
            double sum1=0,sum2=0,sum=0; a=c[1]-48; b=c[3]-48; t=c[2]; if(t=='+')
            {sum1=a+b;}
            if(t=='-')
            {sum1=a-b;}
            if(t=='*')
            {sum1=a*b;}
            if(t=='/')
            {sum1=a/b;} a=c[7]-48; b=c[9]-48; t=c[8]; if(t=='+')
            {sum2=a+b;}
            if(t=='-')
            {sum2=a-b;}
            if(t=='*')
            {sum2=a*b;}
            if(t=='/')
            {sum2=a/b;} a=sum1; b=sum2; t=c[5]; if(t=='+')
            {sum=a+b;}
            if(t=='-')
            {sum=a-b;}
            if(t=='*')
            {sum=a*b;}
            if(t=='/')
            {sum=a/b;} return sum;
            }
            double ans4(char* c)
            {
            char t;
            double a,b;
            double sum1=0,sum2=0,sum=0; a=c[4]-48; b=c[6]-48; t=c[5]; if(t=='+')
            {sum1=a+b;}
            if(t=='-')
            {sum1=a-b;}
            if(t=='*')
            {sum1=a*b;}
            if(t=='/')
            {sum1=a/b;} a=c[1]-48; b=sum1; t=c[2]; if(t=='+')
            {sum2=a+b;}
            if(t=='-')
            {sum2=a-b;}
            if(t=='*')
            {sum2=a*b;}
            if(t=='/')
            {sum2=a/b;} a=sum2; b=c[10]-48; t=c[9]; if(t=='+')
            {sum=a+b;}
            if(t=='-')
            {sum=a-b;}
            if(t=='*')
            {sum=a*b;}
            if(t=='/')
            {sum=a/b;} return sum;
            }double ans5(char* c)
            {
            char t;
            double a,b;
            double sum1=0,sum2=0,sum=0; a=c[4]-48; b=c[6]-48; t=c[5]; if(t=='+')
            {sum1=a+b;}
            if(t=='-')
            {sum1=a-b;}
            if(t=='*')
            {sum1=a*b;}
            if(t=='/')
            {sum1=a/b;} a=sum1; b=c[9]-48; t=c[8]; if(t=='+')
            {sum2=a+b;}
            if(t=='-')
            {sum2=a-b;}
            if(t=='*')
            {sum2=a*b;}


            6楼2013-02-20 21:47
            回复
              if(t=='/')
              {sum2=a/b;} a=c[0]-48; b=sum2; t=c[1]; if(t=='+')
              {sum=a+b;}
              if(t=='-')
              {sum=a-b;}
              if(t=='*')
              {sum=a*b;}
              if(t=='/')
              {sum=a/b;} return sum;
              }double ans6(char* c)
              {
              char t;
              double a,b;
              double sum1=0,sum2=0,sum=0; a=c[6]-48; b=c[8]-48; t=c[7]; if(t=='+')
              {sum1=a+b;}
              if(t=='-')
              {sum1=a-b;}
              if(t=='*')
              {sum1=a*b;}
              if(t=='/')
              {sum1=a/b;} a=c[3]-48; b=sum1; t=c[4]; if(t=='+')
              {sum2=a+b;}
              if(t=='-')
              {sum2=a-b;}
              if(t=='*')
              {sum2=a*b;}
              if(t=='/')
              {sum2=a/b;} a=c[0]-48; b=sum2; t=c[1]; if(t=='+')
              {sum=a+b;}
              if(t=='-')
              {sum=a-b;}
              if(t=='*')
              {sum=a*b;}
              if(t=='/')
              {sum=a/b;} return sum;
              }void fkind(char* a,int n,int i,char* t,char *p)
              {
              static int tot=0;
              if(i==n)
              {
              for(int j=0;j<n;j++)
              {
              // cout<<t[j]<<" ";
              p[tot++]=t[j];
              }
              // cout<<endl;
              // cout<<endl<<tot++<<endl;
              }
              else if(i<n)
              {
              for(int j=0;j<4;j++)
              {
              t[i]=a[j];
              fkind(a,n,i+1,t,p);
              }
              }
              }
              void nkind(int* a,int n,int i,int* t,int *p)
              {
              static int tot=0;
              if(i==n)
              {
              for(int j=0;j<n;j++)
              {
              // cout<<t[j]<<" ";
              p[tot++]=t[j];
              }
              // cout<<endl;
              // cout<<endl<<tot++<<endl;
              }
              else if(i<n)
              {
              for(int j=0;j<4;j++)
              {
              if(a[j]!=-1)
              {
              t[i]=a[j];
              int s=a[j];
              a[j]=-1;
              nkind(a,n,i+1,t,p);
              a[j]=s;
              }
              }
              }
              }
              void equation(int* a,char* b,char* c)
              {
              c[0]=c[1]='(';
              c[5]=c[8]=')';
              c[2]=a[0]+48;
              c[4]=a[1]+48;
              c[7]=a[2]+48;
              c[10]=a[3]+48;
              c[3]=b[0];
              c[6]=b[1];
              c[9]=b[2];
              c[11]='\0';
              }
              void equation3(int* a,char* b,char* c)
              {
              c[0]=c[6]='(';
              c[4]=c[10]=')';
              c[1]=a[0]+48;
              c[3]=a[1]+48;
              c[7]=a[2]+48;
              c[9]=a[3]+48;
              c[2]=b[0];
              c[5]=b[1];
              c[8]=b[2];
              c[11]='\0';
              }
              void equation4(int* a,char* b,char* c)
              {
              c[0]=c[3]='(';
              c[8]=c[7]=')';
              c[1]=a[0]+48;
              c[4]=a[1]+48;
              c[6]=a[2]+48;
              c[10]=a[3]+48;
              c[2]=b[0];
              c[5]=b[1];
              c[9]=b[2];
              c[11]='\0';
              }
              void equation5(int* a,char* b,char* c)
              {
              c[2]=c[3]='(';
              c[10]=c[7]=')';
              c[0]=a[0]+48;
              c[4]=a[1]+48;
              c[6]=a[2]+48;
              c[9]=a[3]+48;
              c[1]=b[0];
              c[5]=b[1];
              c[8]=b[2];
              c[11]='\0';
              }void equation6(int* a,char* b,char* c)
              {
              c[2]=c[5]='(';
              c[10]=c[9]=')';
              c[0]=a[0]+48;
              c[3]=a[1]+48;
              c[6]=a[2]+48;
              c[8]=a[3]+48;
              c[1]=b[0];
              c[4]=b[1];
              c[7]=b[2];
              c[11]='\0';
              }void actoa2(int* a,char (*p)[5],int *sig)
              {
              int i=0;
              for(i=0;i<4;i++)
              {
              if(sig[i]==1)
              {
              if(*(p+i)[0]=='1') a[i]=1;
              if(*(p+i)[0]=='2') a[i]=2;
              if(*(p+i)[0]=='3') a[i]=3;
              if(*(p+i)[0]=='4') a[i]=4;
              if(*(p+i)[0]=='5') a[i]=5;
              if(*(p+i)[0]=='6') a[i]=6;
              if(*(p+i)[0]=='7') a[i]=7;
              if(*(p+i)[0]=='8') a[i]=8;
              if(*(p+i)[0]=='9') a[i]=9;
              }
              else if(sig[i]==2)
              {
              if(p[i][1]=='0'&&*(p+i)[0]=='1') {a[i]=10; }
              if(p[i][1]=='1'&&*(p+i)[0]=='1') {a[i]=11; }
              if(p[i][1]=='2'&&*(p+i)[0]=='1') {a[i]=12; }
              if(p[i][1]=='3'&&*(p+i)[0]=='1') {a[i]=13; }
              }
              else if(sig[i]==0)
              {
              if(*(p+i)[0]=='a'||*(p+i)[0]=='A') a[i]=1;
              if(*(p+i)[0]=='j'||*(p+i)[0]=='J') a[i]=11;
              if(*(p+i)[0]=='q'||*(p+i)[0]=='Q') a[i]=12;
              if(*(p+i)[0]=='k'||*(p+i)[0]=='K') a[i]=13;
              }
              }
              }


              7楼2013-02-20 21:47
              回复
                //接上
                int main()
                {
                // char c[15]; int a[4];
                int sig[4];
                char ac[4][5];
                int num[24][4];
                int tn[4];
                int* pn=num[0];
                char str[64][3];
                char cs[4]={'+','-','*','/'};
                char tc[4];
                char* ps=str[0];
                fkind(cs,3,0,tc,ps);
                cout<<"可以输入字母J,Q,K,A代替11,12,13,1:\n";
                for(int i=0;i<4;i++)
                {
                cin>>ac[i];
                if(ac[i][2]=='\0'&&(ac[i][1]=='1'||ac[i][1]=='2'||ac[i][1]=='3'||ac[i][1]=='0')&&ac[i][0]=='1') sig[i]=2;
                else
                {
                if(ac[i][0]>='1'&&ac[i][0]<='9'&&ac[i][1]=='\0') sig[i]=1;
                else sig[i]=0;
                }
                }
                actoa2(a,ac,sig);
                nkind(a,4,0,tn,pn);
                int i,j;
                int ok=0;
                int tot=0;
                for(i=0;i<24;i++)
                {
                for(j=0;j<64;j++)
                {
                tot++;
                double x=0.0;
                char c[15];
                equation(num[i],str[j],c);
                x=ans2(c);
                if(fabs(x-24.0)<=1e-5)
                {
                ok=1;
                for(int k=0;k<11;k++)
                {
                if(k==2||k==4||k==7||k==10)
                {
                if(c[k]==';') c[k]='J';
                else if(c[k]==':') c[k]='T';
                else if(c[k]=='<') c[k]='Q';
                else if(c[k]=='=') c[k]='K';
                else if(c[k]=='1') c[k]='A';
                }
                }
                for(int k=0;k<11;k++)
                cout<<c[k];
                cout<<"=24"<<endl;
                }
                if(fabs(x-4.0)<=1e-5)
                {
                cout<<"可用阶乘:\n";
                ok=2;
                for(int k=0;k<11;k++)
                {
                if(k==2||k==4||k==7||k==10)
                {
                if(c[k]==';') c[k]='J';
                else if(c[k]==':') c[k]='T';
                else if(c[k]=='<') c[k]='Q';
                else if(c[k]=='=') c[k]='K';
                else if(c[k]=='1') c[k]='A';
                }
                }
                cout<<"(";
                for(int k=0;k<11;k++)
                cout<<c[k];
                cout<<")!=24"<<endl;
                } double y=0.0;
                char d[15];
                equation3(num[i],str[j],d);
                y=ans3(d);
                if(fabs(y-24.0)<=1e-5)
                {
                ok=1;
                for(int k=0;k<11;k++)
                {
                if(k==1||k==3||k==7||k==9)
                {
                if(d[k]==';') d[k]='J';


                8楼2013-02-20 21:50
                回复
                  else if(d[k]==':') d[k]='T';
                  else if(d[k]=='<') d[k]='Q';
                  else if(d[k]=='=') d[k]='K';
                  else if(d[k]=='1') d[k]='A';
                  }
                  }
                  for(int k=0;k<11;k++)
                  cout<<d[k];
                  cout<<"=24"<<endl;
                  }
                  if(fabs(y-4.0)<=1e-5)
                  {
                  cout<<"可用阶乘:\n";
                  ok=2;
                  for(int k=0;k<11;k++)
                  {
                  for(int k=0;k<11;k++)
                  {
                  if(k==1||k==3||k==7||k==9)
                  {
                  if(d[k]==';') d[k]='J';
                  else if(d[k]==':') d[k]='T';
                  else if(d[k]=='<') d[k]='Q';
                  else if(d[k]=='=') d[k]='K';
                  else if(d[k]=='1') d[k]='A';
                  }
                  }
                  }
                  cout<<"(";
                  for(int k=0;k<11;k++)
                  cout<<d[k];
                  cout<<")!=24"<<endl;
                  } double e1=0.0;
                  char e[15];
                  equation4(num[i],str[j],e);
                  e1=ans4(e);
                  if(fabs(e1-24.0)<=1e-5)
                  {
                  ok=1;
                  for(int k=0;k<11;k++)
                  {
                  if(k==1||k==4||k==6||k==10)
                  {
                  if(e[k]==';') e[k]='J';
                  else if(e[k]==':') e[k]='T';
                  else if(e[k]=='<') e[k]='Q';
                  else if(e[k]=='=') e[k]='K';
                  else if(e[k]=='1') e[k]='A';
                  }
                  }
                  for(int k=0;k<11;k++)
                  cout<<e[k];
                  cout<<"=24"<<endl;
                  }
                  if(fabs(e1-4.0)<=1e-5)
                  {
                  cout<<"可用阶乘:\n";
                  ok=2;
                  for(int k=0;k<11;k++)
                  {
                  for(int k=0;k<11;k++)
                  {
                  if(k==1||k==4||k==6||k==10)
                  {
                  if(e[k]==';') e[k]='J';
                  else if(e[k]==':') e[k]='T';
                  else if(e[k]=='<') e[k]='Q';
                  else if(e[k]=='=') e[k]='K';
                  else if(e[k]=='1') e[k]='A';
                  }
                  }
                  }
                  cout<<"(";
                  for(int k=0;k<11;k++)
                  cout<<e[k];
                  cout<<")!=24"<<endl;
                  }


                  9楼2013-02-20 21:50
                  回复
                    double f1=0.0;
                    char f[15];
                    equation5(num[i],str[j],f);
                    f1=ans5(f);
                    if(fabs(f1-24.0)<=1e-5)
                    {
                    ok=1;
                    for(int k=0;k<11;k++)
                    {
                    if(k==0||k==4||k==6||k==9)
                    {
                    if(f[k]==';') f[k]='J';
                    else if(f[k]==':') f[k]='T';
                    else if(f[k]=='<') f[k]='Q';
                    else if(f[k]=='=') f[k]='K';
                    else if(f[k]=='1') f[k]='A';
                    }
                    }
                    for(int k=0;k<11;k++)
                    cout<<f[k];
                    cout<<"=24"<<endl;
                    }
                    if(fabs(f1-4.0)<=1e-5)
                    {
                    cout<<"可用阶乘:\n";
                    ok=2;
                    for(int k=0;k<11;k++)
                    {
                    for(int k=0;k<11;k++)
                    {
                    if(k==0||k==4||k==6||k==9)
                    {
                    if(f[k]==';') f[k]='J';
                    else if(f[k]==':') f[k]='T';
                    else if(f[k]=='<') f[k]='Q';
                    else if(f[k]=='=') f[k]='K';
                    else if(f[k]=='1') f[k]='A';
                    }
                    }
                    }
                    cout<<"(";
                    for(int k=0;k<11;k++)
                    cout<<f[k];
                    cout<<")!=24"<<endl;
                    }
                    double g1=0.0;
                    char g[15];
                    equation6(num[i],str[j],g);
                    g1=ans6(g);
                    if(fabs(g1-24.0)<=1e-5)
                    {
                    ok=1;
                    for(int k=0;k<11;k++)
                    {
                    if(k==0||k==3||k==6||k==8)
                    {
                    if(g[k]==';') g[k]='J';
                    else if(g[k]==':') g[k]='T';
                    else if(g[k]=='<') g[k]='Q';
                    else if(g[k]=='=') g[k]='K';
                    else if(g[k]=='1') g[k]='A';
                    }
                    }
                    for(int k=0;k<11;k++)
                    cout<<g[k];
                    cout<<"=24"<<endl;
                    }
                    if(fabs(g1-4.0)<=1e-5)
                    {
                    cout<<"可用阶乘:\n";
                    ok=2;
                    for(int k=0;k<11;k++)
                    {
                    for(int k=0;k<11;k++)
                    {
                    if(k==0||k==3||k==6||k==8)
                    {
                    if(g[k]==';') g[k]='J';
                    else if(g[k]==':') g[k]='T';
                    else if(g[k]=='<') g[k]='Q';
                    else if(g[k]=='=') g[k]='K';
                    else if(g[k]=='1') g[k]='A';
                    }
                    }
                    }
                    cout<<"(";
                    for(int k=0;k<11;k++)
                    cout<<g[k];
                    cout<<")!=24"<<endl;
                    } }
                    if(ok==1)
                    break;
                    if(tot==1536&&ok==0)
                    cout<<"NO ANSWER!\n";
                    }
                    char ch;
                    cout<<"按任意键结束.....";
                    cin>>ch;
                    return 0;
                    }


                    10楼2013-02-20 21:50
                    回复
                      楼主可帮我生成个工程文件吗?


                      IP属地:广东11楼2014-06-13 22:12
                      回复