當前位置:首頁 » 編程語言 » 24等於多少在c語言中
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

24等於多少在c語言中

發布時間: 2022-05-20 04:18:06

c語言中,024和24是值相等的整型常量嗎

不相等哦。
以0 開頭的是 8進製表示的常數;
以0x開頭的是16進製表示的常數;
沒有前綴的是10進製表示的常數。
所以024和24是不同的
024 也就是 8進制的24,也就是2* 8+4=20
24 也就是10進制的24,也就是2*10+4=24

⑵ 用C語言編程序算24

#include<stdio.h>
#define C case
double fun(double a1,double a2,int b)
{switch(b)
{C 0:return (a1+a2);
C 1:return (a1-a2);
C 2:return (a1*a2);
C 3:return (a1/a2);
}
}
void main()
{ int g;
for(g=0;g<100;)
{int i,j,k,l,n,m,r,save[4];
double num[4]={1,1,1,1},tem1,tem2,tem3,abc=1111;
char sign[5]="+-*/";
printf("請輸入4個數,數字與數字之間用空格隔開:\n");
for(i=0;i<4;i++)
{scanf("%lf",num+i); save[i]=num[i];}
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(j!=i)
{for(k=0;k<4;k++)
if(k!=i&&k!=j)
{for(l=0;l<4;l++)
if(l!=i&&l!=j&&l!=k)
{for(n=0;n<4;n++)
for(m=0;m<4;m++)
for(r=0;r<4;r++)
{tem1=fun(num[i],num[j],n);
tem2=fun(tem1,num[k],m);
tem3=fun(tem2,num[l],r);
if(tem3==24.0)printf("{(%d%c%d)%c%d}%c%d=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);
else if(tem3==-24.0)printf("{%d%c(%d%c%d)}%c%d=24\n",save[k],sign[m],save[i],sign[n],save[j],sign[r],save[l]);
else if(tem3==1.0/24.0)printf("%d%c{(%d%c%d)%c%d}=24\n",save[l],sign[r],save[i],sign[n],save[j],sign[m],save[k]);
else if(tem3==-1.0/24.0)printf("%d%c{%d%c(%d%c%d)}=24\n",save[l],sign[r],save[k],sign[n],save[i],sign[m],save[j]);
else
{tem1=fun(num[i],num[j],n);
tem2=fun(num[k],num[l],r);
tem3=fun(tem1,tem2,m);
if(tem3==24.0) printf("(%d%c%d)%c(%d%c%d)=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);
}
}
}
}
}
g++;
}
}
這個演算法不用講解了吧。。

⑶ C語言24點的演算法

下面是我自己寫的一個程序:

我的解法是把這個問題分解成了兩個子問題,首先求出4個數字的無重復全排列,放到一個數組裡面,再對沒一個排列情況,從頭到尾窮舉所有的四則運算情況。注意到除法是特殊的,我用x/y表示x除以y,用x|y表示x分之y。注意到,如果窮舉的解得到-24的話,只需要把有減法的地方調換一下順序就可以了,代碼如下
/***********************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int index[4]={0,1,2,3};//used to generate subscription collection
int sub[4]; //used in p() only
float f[4]={8.0f,3.0f,3.0f,8.0f};//the 24 point numbers
float fs[24][4];//all possible permutaions of f
float tmp[4]; //used for buf
int g_number=0; //number of permutations
float RES[4];
char op[3];
void p(int idx){//求全排列的函數
if(idx==4){
for(int i=0;i<4;++i){tmp[i]=f[sub[i]];}
for(int g=0;g<g_number;++g){if(memcmp(fs[g],tmp,sizeof(float)*4)==0)return;}
for(int i=0;i<4;++i){fs[g_number][i]=f[sub[i]];}
g_number++;
return;
}
for(int i=0;i<4;++i){//make subscription collections
bool pflag=false;
for(int j=0;j<idx;++j){if(sub[j]==i)pflag=true;}
if(pflag==true)continue;
sub[idx]=index[i];
p(idx+1);
}
}
void solve(int L){//對某個排列,遞歸求所有四則運算的結果,找到就退出
if(L==3){
if(fabs(fabs(RES[L])-24.0f)<0.01f){
printf("Found solution,RES=%f,((%d%c%d)%c%d)%c%d\n",RES[L],
(int)f[0],op[0],
(int)f[1],op[1],
(int)f[2],op[2],
(int)f[3]);
exit(0);
}
return;
}
for(int j=0;j<5;++j){//j judges for operators
if(j==0){RES[L+1]=RES[L]+tmp[L+1];op[L]='+';solve(L+1);}
if(j==1){RES[L+1]=RES[L]-tmp[L+1];op[L]='-';solve(L+1);}
if(j==2){RES[L+1]=RES[L]*tmp[L+1];op[L]='*';solve(L+1);}
if(j==3&&tmp[L+1]!=0)
{RES[L+1]=RES[L]/tmp[L+1];op[L]='/';solve(L+1);}
if(j==4&&RES[L+1]!=0)
{RES[L+1]=tmp[L+1]/RES[L];op[L]='|';solve(L+1);}
}
}
int main(int argc,char* argv[]){//should avoid 0
f[0]=atoi(argv[1]);
f[1]=atoi(argv[2]);
f[2]=atoi(argv[3]);
f[3]=atoi(argv[4]);
p(0);
for(int i=0;i<g_number;++i){
memcpy(tmp,fs[i],sizeof(float)*4);
RES[0]=tmp[0];
for(int t=0;t<4;++t){ printf("%d,",(int)tmp[t]); }
printf("\n");
solve(0);
}
printf("Found no solution :( \n");
return 0;
}

----------編譯運行,運行時的參數就是4個數字
g++ p.cpp && ./a.out 1 5 5 5
1,5,5,5,
Found solution,RES=-24.000000,((1/5)-5)*5
g++ p.cpp && ./a.out 8 3 3 8
8,3,3,8,
Found solution,RES=-24.000006,((8/3)-3)|8
上面這個解寫出來就是
8
--------- = 24
3-(8/3)
主程序為了簡化,省去了對輸入的檢查,樓主可以自己添加。

⑷ 跪求輸入四個數通過 加減乘除計算出24,並顯示出計算過程的C語言程序

#include<stdio.h>
double fun(double a1,double a2,int b)
{switch(b)
{case 0:return (a1+a2);
case 1:return (a1-a2);
case 2:return (a1*a2);
case 3:return (a1/a2);
}
}
void main()
{int i,j,k,l,n,m,r,save[4];
double num[4]={1,1,1,1},tem1,tem2,tem3,abc=1111;
char sign[5]="+-*/";
printf("input 4 numbers:");
for(i=0;i<4;i++)
{scanf("%lf",num+i); save[i]=num[i];}
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(j!=i)
{for(k=0;k<4;k++)
if(k!=i&&k!=j)
{for(l=0;l<4;l++)
if(l!=i&&l!=j&&l!=k)
{for(n=0;n<4;n++)
for(m=0;m<4;m++)
for(r=0;r<4;r++)
{tem1=fun(num[i],num[j],n);
tem2=fun(tem1,num[k],m);
tem3=fun(tem2,num[l],r);
if(tem3==24.0)printf("{(%d%c%d)%c%d}%c%d=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);
else if(tem3==-24.0)printf("{%d%c(%d%c%d)}%c%d=24\n",save[k],sign[m],save[i],sign[n],save[j],sign[r],save[l]);
else if(tem3==1.0/24.0)printf("%d%c{(%d%c%d)%c%d}=24\n",save[l],sign[r],save[i],sign[n],save[j],sign[m],save[k]);
else if(tem3==-1.0/24.0)printf("%d%c{%d%c(%d%c%d)}=24\n",save[l],sign[r],save[k],sign[n],save[i],sign[m],save[j]);
else
{tem1=fun(num[i],num[j],n);
tem2=fun(num[k],num[l],r);
tem3=fun(tem1,tem2,m);
if(tem3==24.0) printf("(%d%c%d)%c(%d%c%d)=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);
}
}
}
}
}
}

⑸ 計算24點 C語言

//24點分析(窮舉法)
//
#include
#include
#include

typedef struct D_NODE
{
int data;
struct D_NODE *left,*right;
} NODE24;
NODE24 head;

int res=24;

int maketree(int *src,int *i, NODE24 *p)
{
int d=src[*i];
(*i)++;
switch (d)
{
case '+':
case '-':
case '*':
case '/':
p->left=new NODE24;
p->right=new NODE24;
p->data=d;
maketree(src,i,p->left);
maketree(src,i,p->right);
break;
default:
p->data=d;
p->left=NULL;
p->right=NULL;
}
return 0;
}

int cmaketree(NODE24 *p)
{
int c;
c=getch();
putchar(c);
switch (c)
{
case '+':
case '-':
case '*':
case '/':
p->left=new NODE24;
p->right=new NODE24;
p->data=c;
cmaketree(p->left);
cmaketree(p->right);
break;
default:
p->data=c-'0';
p->left=NULL;
p->right=NULL;
}
return 0;
}

int work(struct D_NODE *d)
{
int res=0;
if (d->left==NULL&&d->right==NULL)
res=d->data;
else
{
int a,b;
a=work(d->left);
b=work(d->right);
switch (d->data)
{
case '+':
res=a+b;//work(d->left)+work(d->right);
break;
case '-':
res=a-b;//work(d->left)-work(d->right);
break;
case '*':
res=a*b;//work(d->left)*work(d->right);
break;
case '/':
if (b!=0)
res=(a%b==0)?a/b:-79;
else
res=-79;
//res=work(d->right)?work(d->left)/work(d->right):-79;
break;
}
}
return res;
}

int destroy(struct D_NODE *d)
{
if (d->left==NULL&&d->right==NULL)
delete d;
else
{
destroy(d->left);
d->left=NULL;
destroy(d->right);
d->right=NULL;
if (d != &head)
delete d;
}
return 0;
}

int show(struct D_NODE *d)
{
if (d->left==NULL && d->right==NULL)
printf("%d",d->data);
else
{
printf("(");
show(d->left);
printf("%c",d->data);
show(d->right);
printf(")");
}
return 0;
}

/* int input()
{
//int buf[30]=,idx=0;
//maketree(buf,&idx,&head);

int buf[20],idx=0;
printf("\nPlease Input:");
for (idx=0;idx<20;idx++)
{
buf[idx]=getch();
printf("%c",buf[idx]);
}
idx=0;
maketree(buf,&idx,&head);
return 0;
} */

#define test(p1,p2,p3,p4,p5,p6,p7) {exp[0]=(p1),exp[1]=(p2), \
exp[2]=(p3),exp[3]=(p4),exp[4]=(p5),exp[5]=(p6),exp[6]=(p7); \
idx=0; \
maketree(exp,&idx,&head); \
if (work(&head)==res) \
{ \
found++;printf("%5d: ",found);show(&head);\
if (!(found%3)) printf("\n");\
} \
destroy(&head);\
}

// printf("%d,%d,%d,%d,%d,%d,%d\n",p1,p2,p3,p4,p5,p6,p7); \

int test24()
{
int num[4],opc[4]=,exp[20];
int i1,i2,i3,i4,ic1,ic2,ic3,idx,found=0;

char prompt[]="24點游戲分析\n易華衛 12/17/2000\n";
printf("%s",prompt);
for (i1=0;i1<4;i1++)
{
printf("請輸入第%d個數字: ",i1+1);
scanf("%d",num+i1);
//num[i1]=num[i1]%13+1;
}
printf("\n你已經輸入了:%d,%d,%d,%d四個數字!\n",num[0],num[1],num[2],num[3]);
printf("\n請輸入要計算的結果值,(當然二十四點就輸入24啦!):");
scanf("%d",&res);
printf("OK! 按任意鍵就可以開始了!\n");
getch();
for (i1=0;i1<4;i1++)
for (i2=0;i2<4;i2++)
if (i2!=i1)
for (i3=0;i3<4;i3++)
if (i3!=i1&&i3!=i2)
for (i4=0;i4<4;i4++)
if (i4!=i1&&i4!=i2&&i4!=i3)
for (ic1=0;ic1<4;ic1++)
for (ic2=0;ic2<4;ic2++)
for (ic3=0;ic3<4;ic3++)
{
test(opc[ic1],opc[ic2],opc[ic3],num[i1],num[i2],num[i3],num[i4]);
test(opc[ic1],opc[ic2],num[i1],opc[ic3],num[i2],num[i3],num[i4]);
test(opc[ic1],opc[ic2],num[i1],num[i2],opc[ic3],num[i3],num[i4]);
test(opc[ic1],num[i1],opc[ic2],opc[ic3],num[i2],num[i3],num[i4]);
test(opc[ic1],num[i1],opc[ic2],num[i2],opc[ic3],num[i3],num[i4]);
}
printf("\n共找到了 %d 條正確的計算方法!(很抱歉,我沒有處理交換率*^_^*)\n",found);
return 0;
}

main()
{
// fflush(stdin);
// input();
// cmaketree(&head);
// printf("\n=%d\n",work(&head));
test24();
return 0;
}

⑹ C語言算24點

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

char op[3], o[5]="+-*/";

float n[4], on[10];

int used[4] = {0}, top=0, tp=0, x;

void chk(float k);

void search24(int d);

float calc(float n1, float n2, char o);

void make(int i, float p, float q, char o, int d);

int main( void )

{

printf("please input 4 card number: ");

scanf("%f%f%f%f", &n[0], &n[1], &n[2], &n[3]);

search24(0);

printf("No answer. ");

return 0;

}


void chk(float k)

{

if( (tp != 3) || ( fabs(k-24.0) > 0.000001 )) //沒有用完3個運算符或者結果不為24就退出.

return;

for(x=0; x<5; x+=2) //這樣設計是為了使3個選中的符號都可以得到輸出.

printf("%g%c%g=%g ", on[x], op[x/2], on[x+1], //分析得到的.

calc(on[x], on[x+1], op[x/2]));

system("pause");

exit(0);

}

float calc(float n1, float n2, char o)

{

switch(o){

case '+': return (n1+n2);

case '-': return (n1-n2);

case '*': return (n1*n2);

case '/': return (n1/n2);

default: exit(0);

}

}

void make(int i, float p, float q, char o, int d)

{

if(fabs(q)>0.000001 || o!='/') //除數不為0,或者為0的時候不能為除數.

n[i] = calc(p, q, o);

op[tp++] = o;

chk(n[i]);

search24(d+1);

tp--; //因為是全是全局變數,所以在做試驗性的循環遞歸問題時,如果失敗,要在遞歸函數後面重新恢復回原來的值

}

void search24(int d)

{

int i, j, k;

float p, q;

if(d>=3) //控制遞歸深度,就是運算符的輸出個數.

return;

for(i=0; i<4; i++)

for(j=0; j<4; j++)

if( (i!=j)&& (used[i]+used[j] == 0) ) //i!=j是防止重復,(used[i]+used[j] == 0)是防止又再匹配已經用過的j,

//但是i可以新來.

{

used[j] = 1; //j得到匹配之後,賦值為1,表示已經使用

p=n[i];

q=n[j];

on[top++] = p;

on[top++] = q;

for(k=0; k<4; k++) //運算符的循環試用.

make(i, p, q, o[k], d);

n[i] = p; //因為是全是全局變數,所以在做試驗性的循環遞歸問題時,

used[j] = 0; //如果失敗,要在遞歸函數後面重新恢復回原來的值

top -= 2; //

}

}

出處:http://blog.sina.com.cn/s/blog_491de9d60100d5er.html

⑺ 算24 c語言 帶注釋啊

#include<stdio.h>

{
void main ()
int a,b,c;

a=4;
b=6;
c==(a*b);
}

好久沒寫過程序了,我也忘了怎麼寫的了,大概是這樣吧,設置三個變數,給其中的兩個賦值,然後乘法運算,結果給c。那麼c就等於前兩個變數的乘積

⑻ 用C語言快算24,從1到13任意選四個數字,通過加減乘除算得結果為24,數

#include<stdio.h>
double fun(double a1,double a2,int b) //加減乘除的函數
{switch(b)
{case 0:return (a1+a2);
case 1:return (a1-a2);
case 2:return (a1*a2);
case 3:return (a1/a2);
}
}
void main()
{int i,j,k,l,n,m,r,save[4],flg=1;
double num[4]={1,1,1,1},tem1,tem2,tem3,abc=1111;
char sign[5]="+-*/";
printf("輸入四個數:");
for(i=0;i<4;i++) //判斷四個數是否滿足24點運算
{scanf("%lf",num+i); save[i]=num[i];if(save[i]>13)flg=0;}
if(flg) {
flg=0;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(j!=i)
{for(k=0;k<4;k++)
if(k!=i&&k!=j)
{for(l=0;l<4;l++)
if(l!=i&&l!=j&&l!=k)
{for(n=0;n<4;n++)
for(m=0;m<4;m++)
for(r=0;r<4;r++)
{tem1=fun(num[i],num[j],n);
tem2=fun(tem1,num[k],m);
tem3=fun(tem2,num[l],r);
if(tem3==24.0) {printf("{(%d%c%d)%c%d}%c%d=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);return;}
else if(tem3==-24.0) {printf("{%d%c(%d%c%d)}%c%d=24\n",save[k],sign[m],save[i],sign[n],save[j],sign[r],save[l]);return;}
else if(tem3==1.0/24.0) {printf("%d%c{(%d%c%d)%c%d}=24\n",save[l],sign[r],save[i],sign[n],save[j],sign[m],save[k]);return;}
else if(tem3==-1.0/24.0) {printf("%d%c{%d%c(%d%c%d)}=24\n",save[l],sign[r],save[k],sign[n],save[i],sign[m],save[j]);return;}
else
{tem1=fun(num[i],num[j],n);
tem2=fun(num[k],num[l],r);
tem3=fun(tem1,tem2,m);
if(tem3==24.0) {printf("(%d%c%d)%c(%d%c%d)=24\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l]);return;}
}
}
}
}
}
}
if(!flg) printf("
NO
ANSWER\n");
}

⑼ 請問用C語言怎麼算24 盡量給我原代碼 謝謝啊!!

主要是使用逆波蘭表達式的求值。歡迎測試和指正!

[code]
/* cal24.c
* given N integer numbers
* find one expression which proces value T using all
* the N numbers and {+,-,*,/} operators
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 4 /* number of cards */
#define T 24 /* target solution */
#define M 13 /* maximum card value */
#define STACK_SIZE (N+N-1)
#define EPS 1e-6
#define ADD M+1
#define SUB M+2
#define MUL M+3
#define DIV M+4

/* evaluate an expression in reverse Polish notation (RPN) */
double eval(int expr[])
{
double oprnds[N],oprnd1,oprnd2;
int top = -1,i,op;
for(i = 0;i<STACK_SIZE;++i){
op = expr[i];
if(op<=M){
oprnds[++top] = (double)op;
continue;
}
oprnd1 = oprnds[top--];
oprnd2 = oprnds[top--];
switch(op){
case ADD: oprnd1 += oprnd2; break;
case SUB: oprnd1 -= oprnd2; break;
case MUL: oprnd1 *= oprnd2; break;
case DIV:
if(oprnd2<EPS && oprnd2>-EPS) return 0.0;
oprnd1 /= oprnd2;
}
oprnds[++top] = oprnd1;
}
return oprnds[top];
}

int succ(int expr[])
{
double x = eval(expr);
if(x>T-EPS && x<T+EPS) return 1;
return 0;
}

/* just to make the expression more readable by human */
void printsolution(int expr[])
{
double oprnds[N],oprnd1,oprnd2,result;
int top = -1,i,op;
char c;
for(i = 0;i<STACK_SIZE;++i){
op = expr[i];
if(op<=M){
oprnds[++top] = (double)op;
continue;
}
oprnd1 = oprnds[top--];
oprnd2 = oprnds[top--];
switch(op){
case ADD:
c = '+';
result = oprnd1 + oprnd2;
break;
case SUB:
c = '-';
result = oprnd1 - oprnd2;
break;
case MUL:
c = '*';
result = oprnd1 * oprnd2;
break;
case DIV:
c = '/';
result = oprnd1 / oprnd2;
}
printf("%.2f %c %.2f => %.2f\n",oprnd1,c,oprnd2,result);
oprnds[++top] = result;
}
}

/* update ret[] with next possible permutation of N cards */
int permute(int ret[])
{
int orig[N],i,j = 1;
for(i = 0;i<N-1;++i)
if(ret[i]<ret[i+1]){
j = 0;
break;
}
if(j) return 0;
for(i = 0;i<N;++i) orig[i] = ret[i];
for(i = N-2;i>=0;--i)
if(orig[i]<orig[i+1]) break;
for(j = N-1;j>i;--j)
if(orig[j]>orig[i]) break;
ret[i] = orig[j];
orig[j] = orig[i];
for(j = i+1;j<N;++j)
ret[j] = orig[N-j+i];
return 1;
}

/* update ops[] with next possible operators */
int operators(int ops[])
{
int i,j;
for(i = N-1;i>=0;--i){
if(ops[i]<DIV){
++ops[i];
for(j = i+1;j<N-1;++j) ops[j] = ADD;
return 1;
}
}
return 0;
}

/* update expr[] with next possible expression in RPN */
int expressions(int expr[])
{
if(expr[3]>M && expr[4]>M) return 0;
if(expr[2]>M && expr[4]>M) expr[2]^=expr[3]^=expr[2]^=expr[3];
else if(expr[2]>M) expr[4]^=expr[5]^=expr[4]^=expr[5];
else if(expr[3]>M) expr[2]^=expr[3]^=expr[2]^=expr[3];
else expr[3]^=expr[4]^=expr[3]^=expr[4];
return 1;
}

int main(int argc,char *argv[])
{
int opd[N],pmt[N],ops[N-1],expr[STACK_SIZE],i,succeed = 1;
if(argc<N+1) exit(printf("Not enough arguments!\n"));
for(i = 0;i<N;++i) opd[i] = atoi(argv[i+1]);
for(i = 0;i<N;++i) pmt[i] = i;
for(i = 0;i<N-1;++i) ops[i] = ADD;
while(1){
for(i = 0;i<N;++i) expr[i] = opd[pmt[i]];
for(i = 0;i<N-1;++i) expr[N+i] = ops[i];
if(succ(expr)) break;
while(expressions(expr))
if(succ(expr)) break;
if(succ(expr)) break;
if(!operators(ops)){
if(!permute(pmt)){
succeed = 0;
break;
}
for(i = 0;i<N-1;++i) ops[i] = ADD;
}
}
if(!succeed) exit(printf("Find no solutions!\n"));
printsolution(expr);
}

===========================================這里還有一個!TC版
/*在TC2.0下通過,基本實現了24點演算法*/
#include<stdio.h>
#include <conio.h>
int enumerate(int ans);

char op[]={'+','-','*','/'};
char *model[]=
{
"((AxB)yC)zD",
"(Ay(BxC))zD",
"Az(By(CxD))",
"Az((BxC)yD)",
"(AxB)z(CyD)"
};
int *A, *B, *C, *D;
char *x, *y ,*z;
int ***opd;
char ***opr;
char *sample;
int **oprand[]={&A,&B,&C,&D};
char **oprator[]={&x,&y,&z};
int a[4];
int main(void)
{
int i;
printf("Enter %d numbers.\n",4);
for(i=0;i<sizeof a/sizeof a[0];i++)
scanf("%d",a+i);
if(enumerate(24)==0)
printf("No solution!\n");
return 0;
}
int calculate()
{
int v1,v2;
char op;
if(*sample=='A'||*sample=='B'||*sample=='C'||*sample=='D')
v1=***opd++;
else if(*sample=='('){
sample++;
v1=calculate();
}
sample++;
while(*sample=='x'||*sample=='y'||*sample=='z'){
op=***opr++;
sample++;
if(*sample=='A'||*sample=='B'||*sample=='C'||*sample=='D')
v2=***opd++;
else if(*sample=='('){
sample++;
v2=calculate();
}
sample++;
//clrscr();
switch(op)
{
case '+': v1+=v2; break;
case '-' : if(v1<v2) return -1000;
else v1-=v2;break;
case '*': v1*=v2; break;
case '/': if(v2==0||v1%v2!=0)
return -1000;
else v1/=v2; break;
}
}
return v1;
}
int enumerate(int ans)
{
int k;
for(A=a;A<a+4;A++)
for(B=a;B<a+4;B++){
if(B==A) continue;
for(C=a;C<a+4;C++){
if(C==A||C==B)
continue;
D=a+6-(A-a)-(B-a)-(C-a);
for(x=op;x<op+4;x++)
for(y=op;y<op+4;y++)
for(z=op;z<op+4;z++)
for(k=0;k<5;k++){
opd=oprand;
opr=oprator;
sample=model[k];
if(calculate()==ans)
{
opd=oprand;
opr=oprator;
sample=model[k];
while(*sample){
switch(*sample)
{
case 'A':
case 'B':
case 'C':
case 'D':printf("%d",***opd++); break;
case 'x':
case 'y':
case 'z':printf("%c",***opr++);break;
case '(':
case ')':printf("%c",*sample);break;
}
*sample++;
}
printf("=24\n\n");
return 1;
}
}
}
}
return 0;
}