24点大屏代码

合集下载

24点游戏C++ 代码

24点游戏C++ 代码
print(out,obj.Sign[0]);
out<<"("<<obj.Q[1];
print(out,obj.Sign[1]);
out<<obj.Q[2]<<"))";
out<<obj.Q[3]<<"))";
break;
}
default:out<<"方法代码参数错误!!!";
}
out<<"="<<M;
{
Q[0]=a;
Q[1]=b;
Q[2]=c;
Q[3]=d;
method=m;
Sign[0]=s1;
Sign[1]=s2;
Sign[2]=s3;
}
ostream& operator<<(ostream& out,const Four &obj)
bool judge4(double a1,int b1,double a2,int b2,double a3,int b3,double a4);/*a1@((a2@a3)@a4)*/
bool judge5(double a1,int b1,double a2,int b2,double a3,int b3,double a4);/*a1@(a2@(a3@a4))*/
class Four
{
private:
int Sign[3];/*储存运算符*/
int Q[N2];/*储存原始顺序,即未排序前的顺序,是输出函数的依据*/

24点计算器源代码

24点计算器源代码
goto begin;
}
if((a*b)%c==0)
{if(a*b/c+d==24)
{printf("%d*%d/%d+%d=24\n",a,b,c,d);
getchar();
goto begin;
}
if(a*b/c-d==24)
getchar();
goto begin;
}
if(a+b+c-d==24)
{printf("%d+%d+%d-%d=24\n",a,b,c,d);
getchar();
goto begin;
}
if(a*b+c+d==24)
{printf("%d*%d+%d+%d=24\n",a,b,c,d);
SetScreen(0);
printf("请输入4个数字(1-13)");
for(num[aaa=0]=0;num[aaa=0]<1||num[aaa=0]>13;num[aaa=0]=inputn(20));
for(num[aaa=1]=0;num[aaa=1]<1||num[aaa=1]>13;num[aaa=1]=inputn(25));
long value;
char numberc[11];
char string[12];
row=start/20;
col=start%20;
strcpy(numberc,"0bnmghjtyu");
memset(string,0,12);

24点游戏代码

24点游戏代码
{
int i,j,k;
float sum1,sum2,sum3;
for (i=0;i<4;i++)
for (j=0;j<6;j++)
for (k=0;k<6;k++)
{
if ((!(i==3 && b==0)) && (!(j==3 && c==0)) && (!(k==3 && d==0)))
{
sum1=myF(i,a,b);
//printf ("sum2:myF(%d,%2.0f,%2.0f) sum2=%f\n",j,c,d,sum2);
//printf ("2:myF(%d,myF(%d,%2.0f,%2.0f),myF(%d,%2.0f,%2.0f)) sum3=%f\n\n",k,i,a,b,j,c,d,sum3);
sum2=myF(j,sum1,c);
sum3=myF(k,sum2,d);
if (fabs(sum3-24)<0.1)
{
temp++;
myPrint(1,i,j,k,a,b,c,d);
//printf ("sum1:myF(%d,%2.0f,%2.0f) sum1=%f\n",i,a,b,sum1);
}
}
if (k==2)
{
sum1=myF(i,a,b);
sum2=myF(j,c,d);
sum3=sum1*sum2;
if (fabs(sum3-24)<0.1)
{
temp++;

scratch24点计算编程代码

scratch24点计算编程代码

scratch24点计算编程代码以下是一个用Scratch编写的24点计算程序的示例代码:当标志 flag 为2时重置所有变量和列表设置变量 round 为 1设置变量 score 为 0设置列表 cards 为 [1, 2, 3, 4]设置列表 operators 为 ["+", "-", "*", "/"]设置列表 expression 为空列表当标志 flag 为1时如果 round > 3,显示 "游戏结束!你的得分是 " + score,然后停止脚本否则,显示 "第 " + round + " 回合"随机选择一个数字n 从列表cards 中移除并添加到列表expression随机选择一个运算符 op 从列表 operators 中移除并添加到列表expression随机选择一个数字m 从列表cards 中移除并添加到列表expression显示列表 expression等待用户回答如果用户回答为 "24",将 score 增加 10,并显示 "回答正确!你的得分是 " + score否则,显示 "回答错误!正确答案是 " + expression[0] + op + expression[1] + " = 24"将标志 flag 设置为2将 round 增加 1等待 2 秒重置列表 expression重置列表 cards 和 operators将 1、2、3、4 添加回列表 cards将 "+、-、*、/" 添加回列表 operators等待 2 秒将标志 flag 设置为1将标志 flag 设置为1。

c语言实现24点游戏

c语言实现24点游戏

#include "stdio.h"#include "math.h"#include "time.h"void main(){void first();void second();int third();time_t t; /设置机器时间int close=0;char get;clrscr();/清除屏幕缓冲区及液晶显示缓冲区光标位置回到屏幕左上角。

srand((unsigned) time(&t)); /系统时间来初始化for(;;){clrscr();清除屏幕缓冲区及液晶显示缓冲区光标位置回到屏幕左上角printf("24 POINTS SYSTEM v2.2\n"); printf("MADE BY DANTE WANG\n");printf("Jul.28th 2006\n\n");printf("Please choose mode!\n\n");printf("1. Game Mode\n");printf("2. Count Mode\n");printf("3. Quit\n\n");get=getch();等待你按下任意键之后,把该键字符所对应的ASCII码赋给ch,再执行下面的语句switch(get){case '1': first(); break;case '2': second();break;case '3': close=third(); break;default: printf("Please input 1, 2 or 3!\n"); getch(); }if(close)break;}}void first(){int jdgsgn(int a,int b,int c,int d); 1)统计出求不出24的所有组合数目(2)将每一种组合的计算结果写入文件result.txt,每两个组合占一行。

24点游戏C语言代码及报告

24点游戏C语言代码及报告

24点游戏C语言代码及报告24点游戏一,问题分析二十四点游戏规则:给出4个数字,所给数字均为有理数,用加、减、乘、除(可加括号)把给出的数算成24(每个数必须用一次且只能用一次,先算出结果者获胜。

步骤:比如下面的例子:例:3、8、8、9,答案1:(9—8)×8×3答案2: 3×8 ?(9—8)答案3:(9—8?8)×3利用3×8,24、4×6,24求解我的主要想法是首先穷举的可行性问题。

我把表达式如下分成三类—— 1、无括号的简单表达式。

2、有一个括号的简单表达式。

3、有两个括号的较复4、杂表达式。

穷举的开始我对给出的四个数进行排列,其可能的种数为4*3*2*1=24。

我利用一个嵌套函数实现四个数的排列二,源程序及注释//首先穷举的可行性问题。

我把表达式如下分成三类——//1、无括号的简单表达式。

//2、有一个括号的简单表达式。

//3、有两个括号的较复4、杂表达式。

//穷举的开始我对给出的四个数进行排列,其可能的种数为4*3*2*1=24。

我利用一个嵌套函数实现四个数的排列#include <iostream>#include <string>using namespace std;int number=0;string sss[5000];float cal(float a,float b,int p) {switch(p){case 1:return a+b;case 2:return a-b;case 3:return a*b;case 4:return a/b;case 5:return b-a;case 6:return b/a;}}string link(string a,string b,int p) {string st=a;switch(p){case 1:st+=("+"+b);break;case 2:st+=("-"+b);break;case 3:st+=("*"+b);break;case 4:st+=("/"+b);break;case 5:st=b+"-"+st;break;case 6:st=b+"/"+st;break;}st="("+st+")";return st;}void putout1(string c[],int p[]) { string st;st=link(c[1],c[2],p[1]);st=link(st,c[3],p[2]);st=link(st,c[4],p[3]);st=st.erase(0,1);st=st.erase(st.length()-1,1); number++;sss[number]=st;}void putout2(string c[],int p[]) { string st1,st2,st;st1=link(c[1],c[2],p[1]);st2=link(c[3],c[4],p[3]);st=link(st1,st2,p[2]);st=st.erase(0,1);st=st.erase(st.length()-1,1);number++;sss[number]=st;}void suan(float a[],string c[]) {int p[4];int i;float sum,sum1,sum2;for(p[1]=1;p[1]<=6;p[1]++)for(p[2]=1;p[2]<=6;p[2]++)for(p[3]=1;p[3]<=6;p[3]++){sum=cal(a[1],a[2],p[1]);sum=cal(sum,a[3],p[2]);sum=cal(sum,a[4],p[3]);if((sum-24>=0&&sum-24<1e-5)||(sum-24<=0&&sum-24>-1e-5)) putout1(c,p); sum1=cal(a[1],a[2],p[1]);sum2=cal(a[3],a[4],p[3]);sum=cal(sum1,sum2,p[2]);if((sum-24>=0&&sum-24<1e-5)||(sum-24<=0&&sum-24>-1e-5)) putout2(c,p); }}void disorder(float a[],string c[]){float b[5];string d[5];int i,j,k,l;for(i=1;i<=4;i++)for(j=1;j<=4;j++){if(j==i)continue;for(k=1;k<=4;k++){if(k==i||k==j)continue;for(l=1;l<=4;l++){if(l==i||l==j||l==k)continue;b[1]=a[i];b[2]=a[j];b[3]=a[k];b[4]=a[l]; d[1]=c[i];d[2]=c[j];d[3]=c[k];d[4]=c[l]; suan(b,d);}}}}int main(){cout<<"请输入四个数字";float a[5];int i,j;string c[5];for(i=1;i<=4;i++){cin>>a[i];if(a[i]==10)c[i]="10" ;else c[i]=int(a[i])+'0';}disorder(a,c);int v=1,u=0;for(i=1;i<=number;i++){v=1;for(j=1;j<i;j++)if(sss[i]==sss[j])v=0;if(v==1){cout<<sss[i]<<endl;u=1;}}if(u==0)cout<<"无解"<<endl;system("pause");return 0;}三,运行结果显示四,调试和运行程序过程中产生的问题及采取的措施:。

数据结构24点游戏源代码

数据结构24点游戏源代码

#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#define OPSETSIZE 7#define STACK_INIF_SIZE 50#define STACKINCREMENT 10int number[2][4];enum{eNumber = 0, //操作数eOperator = 1 //算子};int oper[7]={43,45,42,47,40,41,35};char OPSET[OPSETSIZE]={'+' , '-' , '*' , '/' ,'(' , ')' , '#'};typedef struct sqlist{int bol;//bol 是0 时,num-ch是一个数字;bol 是1 时num_ch 运算符int num_ch;struct sqlist *next;}sqlist;//线性表typedef struct sqstack{int *base;int *top;int stacksize;}sqstack;//栈的定义unsigned char Prior[7][7] = {// 课本表3.1 算符间的优先关系'>','>','<','<','<','>','>','>','>','<','<','<','>','>','>','>','>','>','<','>','>','>','>','>','>','<','>','>','<','<','<','<','<','=',' ','>','>','>','>',' ','>','>','<','<','<','<','<',' ','='};int init_sq(sqlist *l){//初始化链表l=(sqlist*)malloc(sizeof(sqlist));if(l==NULL){exit(-2);}l->next=NULL;return 1;}int insert_sq(sqlist **p,int e,int bl){//链表插入操作sqlist *q;q=(sqlist*)malloc(sizeof(sqlist));q->num_ch=e;q->bol=bl;q->next=NULL;(*p)->next=q;(*p)=(*p)->next;return 1;}int check(sqlist l)//保证输入的数字是给出的四个数字{int right=1,find=0,i;sqlist *q=&l;q=q->next ;for (;q->next!=NULL;q=q->next){if(q->bol==1){if(q->num_ch <=39||q->num_ch>57||q->num_ch==44||q->num_ch==46){ right=0;printf("%c不是有效的运算符!\n");}}else {find=0;for(i=0;i<4;i++){if(number[1][i]==0&&number[0][i]==q->num_ch ){number[1][i]=1;find=1;break;}}if(find==0){printf("%d 不在给出的四个数字中!\n",q->num_ch );right=0;}}}//end forfor (i=0;i<4;i++){if(number[1][i]==0){printf("%d没有用上!\n",number[0][i]);right=0;}}return right;}int chang(char *s,sqlist *l){//将用户的输入转化为单链表int t=0;unsigned int i=0;int bl,ch;int a1,a2,a;sqlist *p=l;for (;i<strlen(s);i++){if(s[i]>47&&s[i]<58&&t==0){a1=(int)s[i]-48;t++;}else if(s[i]>47&&s[i]<58&&t==1){a2=(int)s[i]-48;a=a1*10+a2;t++;}else if(s[i]<48&&s[i]>39&&s[i]!=44&&s[i]!=46){if(t==1){bl=0;insert_sq(&p,a1,bl);t=0;}else if(t==2){bl=0;insert_sq(&p,a,bl);t=0;}bl=1;ch=(int)s[i];insert_sq(&p,ch,bl);t=0;}else {printf("%c不是有效的运算符!\n",s[i]);}} //end fori=strlen(s)-1;if(s[i]>47&&s[i]<58){if(s[i-1]>47&&s[i-1]<58){bl=0;insert_sq(&p,a,bl);}else {bl=0;insert_sq(&p,a1,bl);}}bl=1;a=35;insert_sq(&p,a,bl);return (check(*l));}int Operate(int a,int theta, int b){//计算switch(theta) {case 43: return a+b;case 45: return a-b;case 42: return a*b;case 47:{if(b==0){return -2000;}if (a%b==0){return a/b;}else {//printf("不能为小数\n");return -10000;}}default : return 0;}}int ReturnOpOrd(char op,char* TestOp)// precede()函数调用求优先级{int i;for(i=0; i< OPSETSIZE; i++){if (op == TestOp[i]) return i;}return 0;}char precede(char Aop, char Bop){return Prior[ReturnOpOrd(Aop,OPSET)][ReturnOpOrd(Bop,OPSET)];}int initstack(sqstack *s){(s)->base = (int*)malloc(STACK_INIF_SIZE*sizeof(int));if((s)->base==NULL) exit(-2);(s)->top=(s)->base;(s)->stacksize = STACK_INIF_SIZE;return 1;}int gettop(sqstack *s){ //取得栈顶元素int e;if(s->top==s->base){printf("栈空,无法取得栈顶元素!\n");return 0;}e=*(s->top-1);return e;}int push(sqstack *s,int e){ //压栈if(s->top-s->base>=s->stacksize){s->base=(int*)realloc(s->base,(s->stacksize+STACKINCREMENT)*sizeof(int));if(!s->base) exit(-2);s->stacksize+= STACKINCREMENT;}*(s->top++)=e;return 1;}int pop(sqstack *s,int *e){ //出栈if(s->top==s->base){printf("栈空,出栈错误!\n");return 0;}*e=*(--s->top);return 1;}int EvaluateExpression(char* MyExpression) { // 算法3.4----计算表达式的值// 算术表达式求值的算符优先算法。

24点程序C#代码(随机方法实现)

24点程序C#代码(随机方法实现)
{
label1.Content = ra.Next(1, 14);
label2.Content = ra.Next(1, 14);
label3.Content = ra.Next(1, 14);
label4.Content = ra.Next(1, 14);
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
double s3 = s1.ran(result5, result6, math2); //s3为抽两个数随机运算,r7没用
double s4 = s1.ran(s3, result7, math3); //s4为最终结果
label5.Content = "";
}
private void button2_Click(object sender, RoutedEventArgs e)
{
yunsuan s1 = new yunsuan(); //s1为运算对象
do { random1 = ra.Next(0, 4); }
while (random1 ==random );
result2 =array [random1 ];
}
for (int i = 0; i < 100000; i++)
{
int math1 = ra.Next(1, 5); //math1为随机运算符1

自己编写的算24点c法度模范代码(解答无重复)[整理版]

自己编写的算24点c法度模范代码(解答无重复)[整理版]

自己编写的算24点c++程序代码(解答无重复)<删除本句话,并将文件后缀改为.cpp>#include <iostream>using namespace std;const double ANS=24;double sourse[4], suan[4];void four(){ if (suan[0]+suan[1]+suan[2]+suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"+"<<suan[2]<<"+"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]*suan[2]*suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"*"<<suan[2]<<"*"<<suan[3]<<"="<<A NS<<endl;}void three(){ if (suan[0]+suan[1]+suan[2]-suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"+"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]*suan[2]+suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"*"<<suan[2]<<"+"<<suan[3]<<"="<<A NS<<endl;if (suan[3]-suan[0]-suan[1]-suan[2]==ANS) cout<<suan[3]<<"-"<<suan[0]<<"-"<<suan[1]<<"-"<<suan[2]<<"="<<A NS<<endl;if (suan[0]*suan[1]*suan[2]-suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"*"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[3]-suan[0]*suan[1]*suan[2]==ANS) cout<<suan[3]<<"-"<<suan[0]<<"*"<<suan[1]<<"*"<<suan[2]<<"="<<A NS<<endl;if (suan[3]/suan[0]/suan[1]/suan[2]==ANS) cout<<suan[3]<<"/"<<suan[0]<<"/"<<suan[1]<<"/"<<suan[2]<<"="<<A NS<<endl;if (suan[0]*suan[1]*suan[2]/suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"*"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;if ((suan[0]+suan[1]+suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"+"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]+suan[1]+suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"+"<<suan[2]<<")/"<<suan[3]<< "="<<ANS<<endl;if (suan[3]/(suan[0]+suan[1]+suan[2])==ANS) cout<<suan[3]<<"/("<<suan[0]<<"+"<<suan[1]<<"+"<<suan[2]<<")="< <ANS<<endl;}void two(){ if (suan[2]-suan[0]*suan[1]-suan[3]==ANS) cout<<suan[2]<<"-"<<suan[0]<<"*"<<suan[1]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[2]/suan[3]+suan[0]+suan[1]==ANS) cout<<suan[2]<<"/"<<suan[3]<<"+"<<suan[0]<<"+"<<suan[1]<<"="<<A NS<<endl;if (suan[2]/suan[0]/suan[1]+suan[3]==ANS) cout<<suan[2]<<"/"<<suan[0]<<"/"<<suan[1]<<"+"<<suan[3]<<"="<<A NS<<endl;if (suan[2]/suan[3]-suan[0]-suan[1]==ANS) cout<<suan[2]<<"/"<<suan[3]<<"-"<<suan[0]<<"-"<<suan[1]<<"="<<ANS<<endl;if (suan[2]/suan[0]/suan[1]-suan[3]==ANS) cout<<suan[2]<<"/"<<suan[0]<<"/"<<suan[1]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[2]-suan[3]/suan[0]/suan[1]==ANS) cout<<suan[2]<<"-"<<suan[3]<<"/"<<suan[0]<<"/"<<suan[1]<<"="<<A NS<<endl;if (suan[2]+suan[0]*suan[1]-suan[3]==ANS) cout<<suan[2]<<"+"<<suan[0]<<"*"<<suan[1]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[0]+suan[1]-suan[2]/suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"-"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]-suan[2]/suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"-"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;if (suan[2]/suan[3]-suan[0]*suan[1]==ANS) cout<<suan[2]<<"/"<<suan[3]<<"-"<<suan[0]<<"*"<<suan[1]<<"="<<A NS<<endl;if (suan[0]*suan[1]/suan[2]-suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"/"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[2]-suan[0]*suan[1]/suan[3]==ANS) cout<<suan[2]<<"-"<<suan[0]<<"*"<<suan[1]<<"/"<<suan[3]<<"="<<A NS<<endl;if ((suan[0]+suan[1])/suan[2]-suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[2]<<"-"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]-suan[3])/suan[0]/suan[1]==ANS) cout<<"("<<suan[2]<<"-"<<suan[3]<<")/"<<suan[0]<<"/"<<suan[1]<< "="<<ANS<<endl;if (suan[2]+(suan[0]+suan[1])/suan[3]==ANS) cout<<suan[2]<<"+("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[2]-(suan[0]+suan[1])*suan[3]==ANS) cout<<suan[2]<<"-("<<suan[0]<<"+"<<suan[1]<<")*"<<suan[3]<<"="< <ANS<<endl;if (suan[2]-(suan[0]+suan[1])/suan[3]==ANS) cout<<suan[2]<<"-("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[2]*(suan[0]+suan[1])+suan[3]==ANS) cout<<suan[2]<<"*("<<suan[0]<<"+"<<suan[1]<<")+"<<suan[3]<<"="< <ANS<<endl;if (suan[2]/(suan[0]+suan[1])+suan[3]==ANS) cout<<suan[2]<<"/("<<suan[0]<<"+"<<suan[1]<<")+"<<suan[3]<<"="< <ANS<<endl;if (suan[2]*(suan[0]+suan[1])-suan[3]==ANS) cout<<suan[2]<<"*("<<suan[0]<<"+"<<suan[1]<<")-"<<suan[3]<<"="< <ANS<<endl;if (suan[2]/(suan[0]+suan[1])-suan[3]==ANS) cout<<suan[2]<<"/("<<suan[0]<<"+"<<suan[1]<<")-"<<suan[3]<<"="< <ANS<<endl;if (suan[2]*(suan[0]+suan[1])/suan[3]==ANS) cout<<suan[2]<<"*("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[2]/(suan[0]+suan[1])/suan[3]==ANS) cout<<suan[2]<<"/("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[0]/(suan[2]-suan[3])*suan[1]==ANS) cout<<suan[0]<<"/("<<suan[2]<<"-"<<suan[3]<<")*"<<suan[1]<<"="< <ANS<<endl;if (suan[0]*(suan[2]-suan[3])*suan[1]==ANS) cout<<suan[0]<<"*("<<suan[2]<<"-"<<suan[3]<<")*"<<suan[1]<<"="< <ANS<<endl;if ((suan[0]+suan[1]-suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"-"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]-suan[0]-suan[1])*suan[3]==ANS) cout<<"("<<suan[2]<<"-"<<suan[0]<<"-"<<suan[1]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]+suan[0]*suan[1])*suan[3]==ANS) cout<<"("<<suan[2]<<"+"<<suan[0]<<"*"<<suan[1]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]-suan[0]*suan[1])*suan[3]==ANS) cout<<"("<<suan[2]<<"-"<<suan[0]<<"*"<<suan[1]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]*suan[1]-suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"*"<<suan[1]<<"-"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]+suan[1]-suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]-suan[0]-suan[1])/suan[3]==ANS) cout<<"("<<suan[2]<<"-"<<suan[0]<<"-"<<suan[1]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]+suan[0]*suan[1])/suan[3]==ANS) cout<<"("<<suan[2]<<"+"<<suan[0]<<"*"<<suan[1]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[2]-suan[0]*suan[1])/suan[3]==ANS) cout<<"("<<suan[2]<<"-"<<suan[0]<<"*"<<suan[1]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]*suan[1]-suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"*"<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<<"="<<ANS<<endl;if (suan[2]/(suan[0]+suan[1]-suan[3])==ANS) cout<<suan[2]<<"/("<<suan[0]<<"+"<<suan[1]<<"-"<<suan[3]<<")="< <ANS<<endl;if (suan[2]/(suan[3]-suan[0]-suan[1])==ANS) cout<<suan[2]<<"/("<<suan[3]<<"-"<<suan[0]<<"-"<<suan[1]<<")="< <ANS<<endl;if (suan[2]/(suan[3]+suan[0]*suan[1])==ANS) cout<<suan[2]<<"/("<<suan[3]<<"+"<<suan[0]<<"*"<<suan[1]<<")="< <ANS<<endl;if (suan[2]/(suan[3]-suan[0]*suan[1])==ANS) cout<<suan[2]<<"/("<<suan[3]<<"-"<<suan[0]<<"*"<<suan[1]<<")="< <ANS<<endl;if (suan[2]/(suan[0]*suan[1]-suan[3])==ANS) cout<<suan[2]<<"/("<<suan[0]<<"*"<<suan[1]<<"-"<<suan[3]<<")="< <ANS<<endl;if ((suan[0]+suan[1])*(suan[2]-suan[3])==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")*("<<suan[2]<<"-"<<suan[3]< <")="<<ANS<<endl;if ((suan[0]+suan[1])/(suan[2]-suan[3])==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")/("<<suan[2]<<"-"<<suan[3]< <")="<<ANS<<endl;}void dou_two(){ if (suan[0]+suan[1]-suan[2]-suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"-"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]+suan[2]+suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"+"<<suan[2]<<"+"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]-suan[2]-suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"-"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]-suan[2]*suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"-"<<suan[2]<<"*"<<suan[3]<<"="<<A NS<<endl;if (suan[0]*suan[1]/suan[2]/suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"/"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;if (suan[0]+suan[1]-suan[2]*suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"-"<<suan[2]<<"*"<<suan[3]<<"="<<A NS<<endl;if ((suan[0]+suan[1])/suan[2]/suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")/"<<suan[2]<<"/"<<suan[3]<< "="<<ANS<<endl;if (suan[2]/(suan[0]+suan[1])*suan[3]==ANS) cout<<suan[2]<<"/("<<suan[0]<<"+"<<suan[1]<<")*"<<suan[3]<<"="< <ANS<<endl;if (suan[2]*(suan[0]+suan[1])*suan[3]==ANS) cout<<suan[2]<<"*("<<suan[0]<<"+"<<suan[1]<<")*"<<suan[3]<<"="< <ANS<<endl;if ((suan[0]+suan[1])/(suan[2]+suan[3])==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")/("<<suan[2]<<"+"<<suan[3]< <")="<<ANS<<endl;}void exp(){if (suan[0]/suan[1]+suan[2]/suan[3]==ANS) cout<<suan[0]<<"/"<<suan[1]<<"+"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;}void ext(){if ((suan[0]-suan[1])*(suan[2]-suan[3])==ANS) cout<<"("<<suan[0]<<"-"<<suan[1]<<")*("<<suan[2]<<"-"<<suan[3]< <")="<<ANS<<endl;}void ex2(){if ((suan[0]+suan[1])*(suan[2]+suan[3])==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<")*("<<suan[2]<<"+"<<suan[3]< <")="<<ANS<<endl;if (suan[0]*suan[1]+suan[2]*suan[3]==ANS) cout<<suan[0]<<"*"<<suan[1]<<"+"<<suan[2]<<"*"<<suan[3]<<"="<<A NS<<endl;}void one(){ if (suan[0]/suan[1]-suan[2]/suan[3]==ANS) cout<<suan[0]<<"/"<<suan[1]<<"-"<<suan[2]<<"/"<<suan[3]<<"="<<A NS<<endl;if (suan[0]+suan[1]/suan[2]-suan[3]==ANS) cout<<suan[0]<<"+"<<suan[1]<<"/"<<suan[2]<<"-"<<suan[3]<<"="<<A NS<<endl;if ((suan[0]-suan[1])/suan[2]-suan[3]==ANS) cout<<"("<<suan[0]<<"-"<<suan[1]<<")/"<<suan[2]<<"-"<<suan[3]<< "="<<ANS<<endl;if (suan[0]-suan[1]/suan[2]-suan[3]==ANS) cout<<suan[0]<<"-"<<suan[1]<<"/"<<suan[2]<<"-"<<suan[3]<<"="<<ANS<<endl;if (suan[0]+(suan[1]-suan[2])/suan[3]==ANS) cout<<suan[0]<<"+("<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[0]*(suan[1]-suan[2])+suan[3]==ANS) cout<<suan[0]<<"*("<<suan[1]<<"-"<<suan[2]<<")+"<<suan[3]<<"="< <ANS<<endl;if (suan[0]/(suan[1]-suan[2])+suan[3]==ANS) cout<<suan[0]<<"/("<<suan[1]<<"-"<<suan[2]<<")+"<<suan[3]<<"="< <ANS<<endl;if (suan[0]*(suan[1]-suan[2])-suan[3]==ANS) cout<<suan[0]<<"*("<<suan[1]<<"-"<<suan[2]<<")-"<<suan[3]<<"="< <ANS<<endl;if (suan[0]/(suan[1]-suan[2])-suan[3]==ANS) cout<<suan[0]<<"/("<<suan[1]<<"-"<<suan[2]<<")-"<<suan[3]<<"="< <ANS<<endl;if (suan[0]*(suan[1]-suan[2])/suan[3]==ANS) cout<<suan[0]<<"*("<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<<"="< <ANS<<endl;if (suan[0]/(suan[1]-suan[2])/suan[3]==ANS) cout<<suan[0]<<"/("<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<<"="< <ANS<<endl;if ((suan[0]+suan[1]/suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"/"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]-suan[1]/suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"-"<<suan[1]<<"/"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]/suan[1]-suan[2])*suan[3]==ANS) cout<<"("<<suan[0]<<"/"<<suan[1]<<"-"<<suan[2]<<")*"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]+suan[1]/suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"+"<<suan[1]<<"/"<<suan[2]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]-suan[1]/suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"-"<<suan[1]<<"/"<<suan[2]<<")/"<<suan[3]<< "="<<ANS<<endl;if ((suan[0]/suan[1]-suan[2])/suan[3]==ANS) cout<<"("<<suan[0]<<"/"<<suan[1]<<"-"<<suan[2]<<")/"<<suan[3]<< "="<<ANS<<endl;if (suan[0]/(suan[1]+suan[2]/suan[3])==ANS) cout<<suan[0]<<"/("<<suan[1]<<"+"<<suan[2]<<"/"<<suan[3]<<")="< <ANS<<endl;if (suan[0]/(suan[1]-suan[2]/suan[3])==ANS) cout<<suan[0]<<"/("<<suan[1]<<"-"<<suan[2]<<"/"<<suan[3]<<")="< <ANS<<endl;if (suan[0]/(suan[1]/suan[2]-suan[3])==ANS) cout<<suan[0]<<"/("<<suan[1]<<"/"<<suan[2]<<"-"<<suan[3]<<")="< <ANS<<endl;if ((suan[0]-suan[1])/(suan[2]-suan[3])==ANS &&(suan[0]-suan[1])*(suan[2]-suan[3])!=0) cout<<"("<<suan[0]<<"-"<<suan[1]<<")/("<<suan[2]<<"-"<<suan[3]< <")="<<ANS<<endl;}int main(){ int i=0, j=0, k=0;int count=0;int tong1; int tong2; int tong3; int butong1; int butong2;int bao1; int bao2; int bao3; int zi1; int zi2;bool flag=false;char ch='y';do{count=0;do {cout <<"请输入四个正整数:";cin >>sourse[0]>>sourse[1]>>sourse[2]>>sourse[3];} while (sourse[0]<1 || sourse[1]<1 || sourse[2]<1 || sourse[3]<1);for (i=0; i<3; i++)for (j=i+1; j<4; j++){ if (sourse[i]==sourse[j]){ count++;if (flag) count++;flag=true;}flag=false;}switch (count){ case 0:for (i=0; i<4; i++){suan[0]=sourse[i];for (j=0; j<4; j++)if (j!=i){suan[1]=sourse[j];for (k=0; k<4; k++)if (k!=i && k!=j){suan[2]=sourse[k];suan[3]=sourse[6-i-j-k]; one();}}}for (i=0; i<6; i++){bao1=i%4; bao2=(i+1+i/4)%4; zi1=(i+2+i/4)%4; zi2=6-bao1-bao2-zi1;suan[0]=sourse[bao1]; suan[1]=sourse[bao2]; suan[2]=sourse[zi1]; suan[3]=sourse[zi2];dou_two(); two();suan[2]=sourse[zi2]; suan[3]=sourse[zi1]; two();}for (i=0; i<3; i++){bao1=i; bao2=(i+1)%3; zi1=(i+2)%3;zi2=6-bao1-bao2-zi1;suan[0]=sourse[bao1]; suan[1]=sourse[bao2]; suan[2]=sourse[zi1]; suan[3]=sourse[zi2];ext(); exp(); ex2();suan[2]=sourse[zi2]; suan[3]=sourse[zi1]; ext(); exp();suan[0]=sourse[bao2]; suan[1]=sourse[bao1]; exp();suan[2]=sourse[zi1]; suan[3]=sourse[zi2];exp();}for (i=0; i<4; i++){bao1=i; bao2=(i+1)%4; bao3=(i+2)%4; zi1=(i+3)%4;suan[0]=sourse[bao1]; suan[1]=sourse[bao2]; suan[2]=sourse[bao3]; suan[3]=sourse[zi1];three();}suan[0]=sourse[0]; suan[1]=sourse[1];suan[2]=sourse[2]; suan[3]=sourse[3];four(); break;case 1:for (i=0; i<3; i++){for (j=i+1; j<4; j++)if (sourse[i]==sourse[j]) break;if (sourse[i]==sourse[j]) break;}tong1=i; tong2=j;for (i=0; i<4; i++)if (i!=tong1 && i!=tong2){butong1=i; butong2=6-tong1-tong2-butong1; break;}suan[0]=sourse[tong1]; suan[1]=sourse[tong2]; suan[2]=sourse[butong1]; suan[3]=sourse[butong2];four(); two(); dou_two(); three(); ext(); exp(); ex2(); one();suan[2]=sourse[butong2]; suan[3]=sourse[butong1]; two(); three(); ext(); exp(); one();suan[0]=sourse[butong1]; suan[1]=sourse[tong1]; suan[2]=sourse[tong2]; suan[3]=sourse[butong2];two(); dou_two(); ext(); exp(); ex2(); one();suan[0]=sourse[butong2]; suan[3]=sourse[butong1]; two(); dou_two(); exp(); one();suan[0]=sourse[butong1]; suan[1]=sourse[butong2]; suan[2]=sourse[tong1]; suan[3]=sourse[tong2];two(); dou_two(); three(); one();suan[0]=sourse[butong2]; suan[1]=sourse[butong1]; one();suan[0]=sourse[tong1]; suan[1]=sourse[butong1]; suan[2]=sourse[butong2]; suan[3]=sourse[tong2];two(); one();suan[1]=sourse[butong2]; suan[2]=sourse[butong1]; two(); one();suan[0]=sourse[tong1]; suan[1]=sourse[butong1]; suan[2]=sourse[tong2]; suan[3]=sourse[butong2];ext(); exp(); one();suan[1]=sourse[butong2]; suan[3]=sourse[butong1]; one();suan[0]=sourse[butong1]; suan[1]=sourse[tong1]; suan[2]=sourse[butong2]; suan[3]=sourse[tong2];exp(); one();suan[0]=sourse[butong2]; suan[2]=sourse[butong1]; one(); break;case 2:for (i=1; i<4; i++)if (sourse[i]==sourse[0]) break;tong1=0; tong2=i;for (i=0; i<4; i++)if (i!=tong1 && i!=tong2){butong1=i; butong2=6-tong1-tong2-butong1; break;}suan[0]=sourse[tong1]; suan[1]=sourse[tong2]; suan[2]=sourse[butong1]; suan[3]=sourse[butong2];four(); two(); dou_two(); ext(); exp(); ex2(); three(); one();suan[0]=sourse[butong1]; suan[1]=sourse[tong1]; suan[2]=sourse[tong2]; suan[3]=sourse[butong2];two(); dou_two(); ext(); exp(); ex2(); one();suan[0]=sourse[butong1]; suan[1]=sourse[butong2]; suan[2]=sourse[tong1]; suan[3]=sourse[tong2];two(); dou_two(); three(); one();suan[0]=sourse[tong1]; suan[1]=sourse[butong1]; suan[2]=sourse[butong2]; suan[3]=sourse[tong2];two(); one();suan[0]=sourse[tong1]; suan[1]=sourse[butong1]; suan[2]=sourse[tong2]; suan[3]=sourse[butong2];ext(); exp(); one();suan[0]=sourse[butong1]; suan[1]=sourse[tong1]; suan[2]=sourse[butong2]; suan[3]=sourse[tong2];exp(); one(); break;case 3:for (i=0; i<4; i++)if(sourse[i]!=sourse[(i+1)%4] &&sourse[i]!=sourse[(i+2)%4]) break;butong1=i; tong1=3-i;for (i=0; i<4; i++)if (i!=butong1 && i!=tong1){tong2=i; tong3=6-tong1-tong2-butong1; break;}suan[0]=sourse[tong1]; suan[1]=sourse[tong2]; suan[2]=sourse[tong3]; suan[3]=sourse[butong1];four(); two(); dou_two(); three(); ext(); exp(); ex2(); one();suan[0]=sourse[tong1]; suan[1]=sourse[tong2]; suan[2]=sourse[butong1]; suan[3]=sourse[tong3];two(); three(); exp(); one();suan[0]=sourse[tong1]; suan[1]=sourse[butong1]; suan[2]=sourse[tong2]; suan[3]=sourse[tong3];two(); dou_two(); one();suan[0]=sourse[butong1]; suan[1]=sourse[tong1]; suan[2]=sourse[tong2]; suan[3]=sourse[tong3];one(); break;case 6:suan[0]=sourse[0]; suan[1]=sourse[1];suan[2]=sourse[2]; suan[3]=sourse[3];four(); two(); dou_two(); three(); ext(); exp(); one();break;}do{cout << "继续?(y/n):"; cin >> ch;} while (ch!='y' && ch!='n' && ch!='Y' && ch!='N');} while (ch=='y' || ch=='Y');return 0;}。

MATLAB计算24点游戏代码

MATLAB计算24点游戏代码

MATLAB计算24点游戏代码第一篇:MATLAB计算24点游戏代码clear,closeall clc a=5;b=7;c=10;d=4;%这里输入需要计算的四个数字a,b,c,d f=[a b c d];tic;g=perms(f);[m,n]=size(g);h='+-*/';fori=1:24 for k1=1:4 for k2=1:4 for k3=1:4str11=[num2str(g(i,1)),h(k1),num2str(g(i,2)),h(k2),num2str(g( i,3)),h(k3),num2str(g(i,4))];str22=['(',num2str(g(i,1)),h(k1),num2str(g(i,2)),')',h(k2),num2s tr(g(i,3)),h(k3),num2str(g(i,4))];str33=['(',num2str(g(i,1)),h(k1),num2str(g(i,2)),h(k2),num2str( g(i,3)),')',h(k3),num2str(g(i,4))];str44=['(',num2str(g(i,1)),h(k1),num2str(g(i,2)),')',h(k2),'(',nu m2str(g(i,3)),h(k3),num2str(g(i,4)),')',];A=str2num(str11);B=str2n um(str22);C=str2num(str33);D=str2num(str44);ifA==24||B==24||C==24||D==24 break else end endif A==24||B==24||C==24||D==24 break else end endif A==24||B==24||C==24||D==24 break else end endif A==24||B==24||C==24||D==24 break else end endif A==24answer=str11;elseif B==24answer=str22;elseif C==24answer=str33;elseif D==24answer=str44;elseanswer='无解';enddisp(['计算方法',num2str(answer)])time=toc;disp(['计算耗时',num2str(time),'s'])第二篇:人脸识别MATLAB代码1.色彩空间转换function[r,g]=rgb_RGB(Ori_Face)R=Ori_Face(:,:,1);G=Ori_Face(:,:,2);B=Ori_ Face(:,:,3);R1=im2double(R);% 将uint8型转换成double型G1=im2double(G);B1=im2double(B);RGB=R1+G1+B1;row=size(Ori_Face,1);% 行像素 column=size(Ori_Face,2);% 列像素 for i=1:row for j=1:columnrr(i,j)=R1(i,j)/RGB(i,j);gg(i,j)=G1(i,j)/RGB(i,j);end end rrr=mean(rr);r=mean(rrr);ggg=mean(gg);g=mean(ggg);2.均值和协方差t1=imread('D:matlab皮肤库1.jpg');[r1,g1]=rgb_RGB(t1);t2=imread('D:matlab皮肤库2.jpg');[r2,g2]=rgb_RGB(t2);t3=imread('D:matlab皮肤库3.jpg');[r3,g3]=rgb_RGB(t3);t4=imread('D:matlab皮肤库4.jpg');[r4,g4]=rgb_RGB(t4);t5=imread('D:matlab皮肤库5.jpg');[r5,g5]=rgb_RGB(t5);t6=imread('D:matlab皮肤库6.jpg');[r6,g6]=rgb_RGB(t6);t7=imread('D:matlab皮肤库7.jpg');[r7,g7]=rgb_RGB(t7);t8=imread('D:matlab皮肤库8.jpg');[r8,g8]=rgb_RGB(t8);t9=imread('D:matlab皮肤库9.jpg');[r9,g9]=rgb_RGB(t9);t10=imread('D:matlab皮肤库10.jpg');[r10,g10]=rgb_RGB(t10);t11=imread('D:matlab皮肤库11.jpg');[r11,g11]=rgb_RGB(t11);t12=imread('D:matlab皮肤库12.jpg');[r12,g12]=rgb_RGB(t12);t13=imread('D:matlab皮肤库13.jpg');[r13,g13]=rgb_RGB(t13);t14=imread('D:matlab皮肤库14.jpg');[r14,g14]=rgb_RGB(t14);t15=imread('D:matlab皮肤库15.jpg');[r15,g15]=rgb_RGB(t15);t16=imread('D:matlab皮肤库16.jpg');[r16,g16]=rgb_RGB(t16);t17=imread('D:matlab皮肤库17.jpg');[r17,g17]=rgb_RGB(t17);t18=imread('D:matlab皮肤库18.jpg');[r18,g18]=rgb_RGB(t18);t19=imread('D:matlab皮肤库19.jpg');[r19,g19]=rgb_RGB(t19);t20=imread('D:matlab皮肤库20.jpg');[r20,g20]=rgb_RGB(t20);t21=imread('D:matlab皮肤库21.jpg');[r21,g21]=rgb_RGB(t21);t22=imread('D:matlab皮肤库22.jpg');[r22,g22]=rgb_RGB(t22);t23=imread('D:matlab皮肤库23.jpg');[r23,g23]=rgb_RGB(t23);t24=imread('D:matlab皮肤库24.jpg');[r24,g24]=rgb_RGB(t24);t25=imread('D:matlab皮肤库25.jpg');[r25,g25]=rgb_RGB(t25);t26=imread('D:matlab皮肤库26.jpg');[r26,g26]=rgb_RGB(t26);t27=imread('D:matlab皮肤库27.jpg');[r27,g27]=rgb_RGB(t27);r=cat(1,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17 ,r18,r19,r20,r21,r22,r23,r24,r25,r26,r27);g=cat(1,g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,g12,g13,g14,g1 5,g16,g17,g18,g19,g20,g21,g22,g23,g24,g25,g26,g27);m=mean( [r,g])n=cov([r,g])3.求质心function [xmean, ymean] = center(bw)bw=bwfill(bw,'holes');area = bwarea(bw);[m n] =size(bw);bw=double(bw);xmean =0;ymean = 0;for i=1:m, for j=1:n,xmean = xmean + j*bw(i,j);ymean = ymean + i*bw(i,j);end;end;if(area==0)xmean=0;ymean=0;elsexmean = xmean/area;ymean = ymean/area;xmean = round(xmean);ymean = round(ymean);end4.求偏转角度function [theta] = orient(bw,xmean,ymean)[m n]=size(bw);bw=double(bw);a = 0;b = 0;c = 0;for i=1:m, for j=1:n,a = a +(jxmean)*(iymean)^2 * bw(i,j);end;end;b = 2 * b;theta = atan(b/(a-c))/2;theta = theta*(180/pi);% 从幅度转换到角度 5.找区域边界function [left, right, up, down] = bianjie(A)[m n] = size(A);left =-1;right =-1;up =-1;down =-1;for j=1:n,for i=1:m,if(A(i,j)~= 0) left = j;break;end;end;if(left ~=-1)break;end;end;for j=n:-1:1, for i=1:m, if(A(i,j)~= 0)right = j;break;end;end;if(right ~=-1)break;end;end;for i=1:m, for j=1:n,if(A(i,j)~= 0) up = i;break;end;end;if(up ~=-1)break;end;end;for i=m:-1:1,for j=1:n,if(A(i,j)~= 0)down = i;break;end;end;if(down ~=-1)break;end;end;6.求起始坐标function newcoord = checklimit(coord,maxval)newcoord = coord;if(newcoord<1)newcoord=1;end;if(newcoord>maxval)newcoord=maxval;end;7.模板匹配function [ccorr, mfit, RectCoord] = mobanpipei(mult, frontalmodel,ly,wx,cx, cy, angle)frontalmodel=rgb2gray(frontalmodel);model_rot = imresize(frontalmodel,[ly wx],'bilinear');% 调整模板大小 model_rot = imrotate(model_rot,angle,'bilinear');% 旋转模板 [l,r,u,d] = bianjie(model_rot);% 求边界坐标 bwmodel_rot=imcrop(model_rot,[l u(r-l)(d-u)]);% 选择模板人脸区域 [modx,mody] =center(bwmodel_rot);% 求质心 [morig, norig] = size(bwmodel_rot);% 产生一个覆盖了人脸模板的灰度图像mfit = zeros(size(mult));mfitbw = zeros(size(mult));[limy, limx] = size(mfit);% 计算原图像中人脸模板的坐标 startx = cx-modx;starty = cy-mody;endx = startx + norig-1;endy = starty + morig-1;startx = checklimit(startx,limx);starty = checklimit(starty,limy);endx = checklimit(endx,limx);endy = checklimit(endy,limy);for i=starty:endy, for j=startx:endx,mfit(i,j)= model_rot(i-starty+1,j-startx+1);end;end;ccorr = corr2(mfit,mult)% 计算相关度 [l,r,u,d] = bianjie(bwmodel_rot);sx = startx+l;sy = starty+u;RectCoord = [sx sy(r-1)(d-u)];% 产生矩形坐标 8.主程序 clear;[fname,pname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.gif'},'Please choose a color picture...');% 返回打开的图片名与图片路径名 [u,v]=size(fname);y=fname(v);% 图片格式代表值switch ycase 0errordlg('You Should Load Image File First...','Warning...');case{'g';'G';'p';'P';'f';'F'};% 图片格式若是JPG/jpg、BMP/bmp、TIF/tif或者GIF/gif,才打开I=cat(2,pname,fname);Ori_Face=imread(I);subplot(2,3,1),imshow(Ori_Face);otherwiseerrordlg('You Should Load Image File First...','Warning...');end R=Ori_Face(:,:,1);G=Ori_Face(:,:,2);B=Ori_Face(:,:,3);R1=im2double(R);% 将uint8型转换成double型处理G1=im2double(G);B1=im2double(B);RGB=R1+G1+B1;m=[ 0.4144,0.3174];% 均值 n=[0.0031,-0.0004;-0.0004,0.0003];% 方差 row=size(Ori_Face,1);% 行像素数 column=size(Ori_Face,2);% 列像素数 for i=1:rowfor j=1:columnif RGB(i,j)==0rr(i,j)=0;gg(i,j)=0;elserr(i,j)=R1(i,j)/RGB(i,j);gg(i,j)=G1(i,j)/RGB(i,j);x=[rr(i,j),gg(i,j)];p(i,j)=exp((-0.5)*(x-m)*inv(n)*(x-m)');endend endsubplot(2,3,2);imshow(p);low_pass=1/9*ones(3);image_low=filter2(low_pass, p);subplot(2,3,3);imshow(image_low);% 自适应阀值程序previousSkin2 = zeros(i,j);changelist = [];for threshold = 0.55:-0.1:0.05 two_value = zeros(i,j);two_value(find(image_low>threshold))= 1;change = sum(sum(two_valuel +1);% 宽度 ly =(d-u + 1);% 高度 wratio = ly/wx% 高宽比if((0.8<=wratio)&(wratio<=2))% 如果目标区域的高度/宽度比例大于0.8且小于2.0,则将其选出进行下一步运算S=ly*wx;% 计算包含此区域矩形的面积A=bwarea(bwsegment);% 计算此区域面积if(A/S>0.35)[ccorr,mfit, RectCoord] = mobanpipei(justface,frontalmodel,ly,wx, cx,cy, angle);endif(ccorr>=0.6)mfitbw=(mfit>=1);invbw = xor(mfitbw,ones(size(mfitbw)));source_with_hole = uint8(double(invbw).* double(imsourcegray));final_image = uint8(double(source_with_hole)+ double(mfit));subplot(2,3,5);imshow(final_image);% 显示覆盖了模板脸的灰度图像imsourcegray = final_image;subplot(2,3,6);imshow(Ori_Face);% 显示检测效果图end;if(RectCoord ~=-1)FaceCoord = [FaceCoord;RectCoord];endend end end% 在认为是人脸的区域画矩形[numfaces x] = size(FaceCoord);for i=1:numfaces,hd = rectangle('Position',FaceCoord(i,:));set(hd, 'edgecolor', 'y');end 人脸检测是人脸识别、人机交互、智能视觉监控等工作的前提。

24点纸牌游戏源代码

24点纸牌游戏源代码

#include <stdio.h>#include <windows.h>#pragma comment ( lib, "Winmm.lib")// 0,1,2,3分别代表+,-,*,/float OperVisual(float num1,float num2,int oper);//双目运算int Show(float num1,float num2,float num3,float num4,int i);//交换率运算并显示void main(){int i1,i2,i3,i4,i=0;unsigned int s1,s2;float num[4];//分别代表输入的4个数puts("Please enter the number 4:");scanf("%f%f%f%f",&num[0],&num[1],&num[2],&num[3]);s1=timeGetTime();for(i1=0;i1<4;i1++){for(i2=0;i2<4;i2++){for(i3=0;i3<4;i3++){for(i4=0;i4<4;i4++){if(i1!=i2&&i1!=i3&&i1!=i4&&i2!=i3&&i2!=i4&&i3!=i4)i=Show(num[i1],num[i2],num[i3],num[i4],i);}}}}if(!i) printf("No answer !");s2=timeGetTime();printf("\ntime consuming:%dms\n",s2-s1);getchar();getchar();}int Show(float num1,float num2,float num3,float num4,int i){int oper1,oper2,oper3;//分别代表3个操作符char OperShow[4]={'+','-','*','/'};//0,1,2,3float end1,end2,end3;for(oper1=0;oper1<4;oper1++){//第一个运算符end1=OperVisual(num1,num2,oper1);//将第一个数进行4次运算for(oper2=0;oper2<4;oper2++){//第二个运算符end2=OperVisual(end1,num3,oper2);//将前两个数的结果和第三个数进行4次运算for (oper3=0;oper3<4;oper3++){//第三个运算符end3=OperVisual(end2,num4,oper3);//将前三个数的结果和第三个数进行4次运算if(end3==24){if(oper1<=1&&oper2>=2)//如果第一个运算符为+或-第二个运算符为*或/printf("(%.f%c%.f)%c%.f%c%.f=24\n",num1,OperShow[oper1],num2,OperShow[oper2],nu m3,OperShow[oper3],num4),i++;else if(oper1<=1&&oper2<=1&&oper3>=2)printf("(%.f%c%.f%c%.f)%c%.f=24\n",num1,OperShow[oper1],num2,OperShow[oper2],nu m3,OperShow[oper3],num4),i++;else if(oper1>=2&&oper2<=1&&oper3>=2)printf("(%.f%c%.f%c%.f)%c%.f=24\n",num1,OperShow[oper1],num2,OperShow[oper2],nu m3,OperShow[oper3],num4),i++;elseprintf("%.f%c%.f%c%.f%c%.f=24\n",num1,OperShow[oper1],num2,OperShow[oper2],num3,Op erShow[oper3],num4),i++;}}}}return i;}float OperVisual(float num1,float num2,int oper){float result;switch(oper){case 0:result=num1+num2;break;case 1:result=num1-num2;break;case 2:result=num1*num2;break;case 3:result=num1/num2;break;}return result;}。

24点生成计算VBA代码

24点生成计算VBA代码

24点生成计算VBA代码Dim iRndCardsNumber(4) As SingleSub Macro1()Dim i As Integer, j As IntegerDim b As BooleanRandomizei = 1b = TrueSheets("sheet1").Cells.SelectSelection.ClearContentsDo While b = TrueiRndCardsNumber(1) = Int(Rnd * 10 + 1)iRndCardsNumber(2) = Int(Rnd * 10 + 1)iRndCardsNumber(3) = Int(Rnd * 10 + 1)iRndCardsNumber(4) = Int(Rnd * 10 + 1)iAnswer = Operator()If iAnswer <> "" ThenSheets("sheet1").Range("a" & i) = iRndCardsNumber(1) & "," & iRndCardsNumber(2) & "," & iRndCardsNumber(3) & "," & iRndCardsNumber(4)i = i + 1If i > 25 Then b = FalseEnd IfLoopi = 1b = TrueDo While b = TrueiRndCardsNumber(1) = Int(Rnd * 10 + 1)iRndCardsNumber(2) = Int(Rnd * 10 + 1)iRndCardsNumber(3) = Int(Rnd * 10 + 1)iRndCardsNumber(4) = Int(Rnd * 10 + 1)iAnswer = Operator()If iAnswer <> "" ThenSheets("sheet1").Range("c" & i) = iRndCardsNumber(1) & "," & iRndCardsNumber(2) & "," & iRndCardsNumber(3) & "," & iRndCardsNumber(4)i = i + 1If i > 25 Then b = FalseEnd IfLoopEnd SubFunction Operator() As StringDim a As IntegerDim b As IntegerDim c As IntegerDim d As IntegerDim op1 As IntegerDim op2 As IntegerDim op3 As IntegerDim answer1 As SingleDim answer2 As SingleDim answer3 As SingleDim t1l As String, t1r As String, t2l As String, t2r As String '四个变量分别表示为:第一个左括号,第一个右括号,第二个左括号,第二个右括号Operator = "" '如果程序执行到此处那么所给的点数将是一种无解的状态For a = 1 To 4 '得For b = 1 To 4 '到If b <> a Then 'abcdFor c = 1 To 4 '的If (c <> a) And (c <> b) Then '组For d = 1 To 4 '合If (d <> a) And (d <> b) And (d <> c) Then '共有4!=24种组合For op1 = 1 To 4 'For op2 = 1 To 4 'For op3 = 1 To 4 '得到运算符的排序共有4*4*4=64种'到处可以得到24*64=1536种表达式的排序顺序而由于运算符的优先级问题,使得每种表达式又有'5种的运算顺序而最终就可以得到1536*5=7680的输出情况,但我们就只需一种结果等于24的。

MFC 24点程序代码及注释

MFC 24点程序代码及注释
if( buf1[j] == 'T' )
printf("10 ");
else
printf("%c ", buf1[j]);
}
printf("\n按任意键参考答案...\n");
getch();
if( TryResolve(buf1, buf2) ) // 解题
sum=MyCalcu(p[0],MyCalcu(MyCalcu(p[1],p[2],oper[1]),p[3],oper[2]),oper[0]); //A*((B*C)*D)
break;
case 2:
sum=MyCalcu(MyCalcu(p[0],p[1],oper[0]),MyCalcu(p[2],p[3],oper[2]),oper[1]); // (A*B)*(C*D)
srand( (unsigned)time( NULL ) );
char buf1[4]; // 题目
char buf2[30]; // 解答
printf("***************************\n");
printf("计算24\n");
printf("A J Q K 均按1计算,其它按牌点计算\n");
break;
case 3:
sum=MyCalcu(MyCalcu(MyCalcu(p[0],p[1],oper[0]),p[2],oper[1]),p[3],oper[2]); //((A*B)*C)*D
break;
case 4:
sum=MyCalcu(MyCalcu(p[0],MyCalcu(p[1],p[2],oper[1]),oper[0]),p[3],oper[2]); //(A*(B*C))*D

c语言小程序24点思路与代码

c语言小程序24点思路与代码

24点游戏使用说明书程序操作说明(1)在机器上装好TC2.0环境,读者在下载后直接解压到C盘即可。

(2)运行TC文件夹中的TC.exe文件,打开TC环境。

键盘上按下“F10”键,切换到菜单功能,使用方向键移动到File菜单,按向下方向键展开File菜单,按向下方向键,选择Load菜单项,按下回车键,输入文件所在路径及文件名称。

将源码导入到TC环境中。

(3)按键盘“F9”进行编译,然后按“Ctrl+F9”组合键运行程序。

24点游戏界面比较简单,没有复杂的操作。

读者掌握游戏规则后。

运行程序后进入到24点游戏的功能菜单界面。

在此界面可以选择开始游戏,查看游戏规则或者退出游戏3个选项,其效果如下图所示。

24点游戏功能菜单界面在功能菜单界面输入数字2可以查看游戏规则。

游戏规则界面如下图所示。

戏规则界面在功能菜单界面输入数字1便进入游戏界面,即可按照要求进行游戏,游戏界面如下图所示。

游戏运行界面代码如下(tc环境下)#include <stdio.h>double operation(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, n;while (1){clrscr();gotoxy(15, 6); /*将光标定位*/printf("1.start game?(y/n)");gotoxy(15, 8);printf("2.Rule");gotoxy(15, 10);printf("3.exit\n");gotoxy(25, 15);printf("please choose:");scanf("%d", &i);switch (i){case 1:clrscr();start();break;case 2:/*输出游戏规则*/clrscr();printf("\t\tThe Rules Of The Game\n");printf(" step1: input 4 digits\n");printf(" step2: Reflections on 10 seconds\n");printf(" step3: use the + - * /and the 4 digits to make expression which the result is 24\n");sleep(10);break;case 3:/*退出游戏*/exit(0);default:break;}}}start(){int i, j, k, l, n, m, r,data[4],a[4]={0};double num[4] ={0}, res1, res2, res3;char sign[5] = "+-*/",ch;printf("input 4 numbers:");for (i = 0; i < 4; i++){scanf("%lf", num + i);/*从键盘中输入要进行24点游戏的数字*/data[i] = num[i];}printf("Reflections on 10 seconds,input your answer:\n");sleep(10);/*程序暂停10秒钟*/printf("please input your result:\n");for(i=1;i<=3;i++){scanf("%d",&a[2]);scanf("%c",&ch);scanf("%d",&a[3]);switch(ch)/*根据运算符进行运算*/{case '+':a[1]=a[2]+a[3];break;case '-':a[1]=a[2]-a[3];break;case '*':a[1]=a[2]*a[3];break;case '/':a[1]=a[2]/a[3];break;}printf("%d%c%d=%d\n",a[2],ch,a[3],a[1]);/*输出计算过程*/}if(a[1]==24)printf("you are right!\n");elseprintf("sorry,you are worry!\n");printf("press any key to see all the answers:\n");getch();printf("the result is:\n");/*输出所有结果*/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++){res1 = operation(num[i], num[j], n);res2 = operation(res1, num[k], m);res3 = operation(res2, num[l], r);if (res3 == 24.0)printf("[(%d%c%d)%c%d]%c%d=24\n", data[i],sign[n], data[j], sign[m], data[k], sign[r],data[l]);/*若结果为24则按正常顺序输出*/else if (res3 == - 24.0)printf("[%d%c(%d%c%d)]%c%d=24\n",data[k],sign[m],data[i], sign[n], data[j], sign[r],data[l]);/*调整输出顺序*/else if (res3 == 1.0 / 24.0)printf("%d%c[(%d%c%d)%c%d]=24\n", data[l],sign[r], data[i], sign[n],data[j], sign[m],data[k]);/*调整输出顺序*/else if (res3 == - 1.0 / 24.0)printf("%d%c[%d%c(%d%c%d)]=24\n", data[l],sign[r], data[k], sign[n], data[i], sign[m],data[j]);/*调整输出顺序*/else{res1 = operation(data[i], data[j], n);res2 = operation(data[k], data[l], r);res3 = operation(res1, res2, m);if (res3 == 24.0)/*判断结果是否为24*/printf("(%d%c%d)%c(%d%c%d)=24\n", data[i],sign[n], data[j], sign[m], data[k],sign[r], data[l]);}}}}}getch();}。

算24点源代码

算24点源代码

#include<stdio.h>#include<stdlib.h>#define Shujugeshu 10int tiny_main(int Tezhengzhi, FILE* fp_total);int heart(float fours[4], int dingwei[6], int Tezhengzhi); /*核心程序,处理一组数*/void myprint(int xuhao, int* jishu, float fours[4], int dingwei[6], FILE*fp); /*打印结果*/void AAA_maker(float fours[4], float AAA[6][6][3]); /*AAA制造者*/void BBB_maker(float AAA[6][6][3], float BBB[6][6][3][6][2], int x1, int x2); /*BBB制造者*/void CCC_maker(float BBB[6][6][3][6][2], float CCC[6][6][3][6][6], int x1, intx2, int x3, int x4, int dingwei[6], int Tezhengzhi); /*CCC制造者*/void sixs_maker(float m1, float m2, float sixs[6]); /*两个数加减乘(被乘)除(被除)六种运算出结果*/int main(){int Tezhengzhi;FILE* fp_total;if((fp_total=fopen("/Users/shengdian/Documents/C/算24/total.txt","wt"))==NULL){printf("Fail openning file!\n");return -1;}for (Tezhengzhi=-1000; Tezhengzhi<=1000; Tezhengzhi++)tiny_main(Tezhengzhi,fp_total);fclose(fp_total);return1;}int tiny_main(int Tezhengzhi, FILE* fp_total){int m1, m2, m3, m4; /*用于运算的四个数的序号*/int xuhao, i, jishu; /*每种排列的序号,,成功数目*/float QiQi[4*Shujugeshu]; /*1到Shujugeshu共十个数,每个数字出现4次*/float fours[4]; /*存储四个数的数组*/int dingwei[6]; /*定位记号,前5个为坐标,最后一个为1代表有解*/FILE *fp; /*输出文件*/char file_name[50]="/Users/shengdian/Documents/C/算24/11/";char file_name_add[20];sprintf(file_name_add, "%d.txt", Tezhengzhi);strcat(file_name, file_name_add);if((fp=fopen(file_name, "wt"))==NULL){printf("Fail openning file!\n");return -1;}for(i=1;i<=Shujugeshu;i++) /*数据初始化*/QiQi[4*i-4]=QiQi[4*i-3]=QiQi[4*i-2]=QiQi[4*i-1]=i;xuhao=1;jishu=0;for(m1=0; m1<4*Shujugeshu; m1++)for(m2=m1+1; m2<4*Shujugeshu; m2++)for(m3=m2+1; m3<4*Shujugeshu; m3++)for(m4=m3+1; m4<4*Shujugeshu; m4++) /*相当于在4*NN张牌中选择4张牌*/{fours[0]=QiQi[m1];fours[1]=QiQi[m2];fours[2]=QiQi[m3];fours[3]=QiQi[m4];heart(fours, dingwei, Tezhengzhi);myprint(xuhao, &jishu, fours, dingwei, fp);xuhao++;}xuhao--;fprintf(fp, "\n~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n");fprintf(fp,"\nTezhengzhi\t:\t%d\nTotal\t\t:\t%d\nSuccess\t\t:\t%d\nSuccessRate\t:\t%2.2f%%\n", Tezhengzhi, xuhao, jishu,100.0*(float)jishu/(float)xuhao);fclose(fp);fprintf(fp_total, "%d\t\t%d\t\t%2.2f\n", Tezhengzhi, jishu,100.0*(float)jishu/(float)xuhao);return1;}int heart(float fours[4], int dingwei[6], int Tezhengzhi) /*判断一组四个数是否有解,并求具体解*/{float AAA[6][6][3], BBB[6][6][3][6][2], CCC[6][6][3][6][6]; /*4C2=6, 3C2=3, 2C2=1*/int x1, x2, x3, x4; /*四个坐标*/dingwei[5]=-1;AAA_maker(fours, AAA); /*第一步*/for(x1=0; x1<=5; x1++)for(x2=0; x2<=5; x2++)BBB_maker(AAA, BBB, x1, x2); /*第二步*/for(x1=0; x1<=5; x1++)for(x2=0; x2<=5; x2++)for(x3=0; x3<=2; x3++)for(x4=0; x4<=5; x4++) /*第三步*/{dingwei[5]=-1;CCC_maker(BBB, CCC, x1, x2, x3, x4, dingwei, Tezhengzhi);if(dingwei[5]==1)return1; /*算出24,立即返回*/}return -1;}void AAA_maker(float fours[4], float AAA[6][6][3]) /*AAA是存储的第一步运算结果*/{int x2;float sixs[6];/*前两个数不参与运算,后两个数参与运算*/ sixs_maker(fours[0], fours[1], sixs); /*2,3,(0,1)*/for(x2=0; x2<=5; x2++){AAA[0][x2][0]=fours[2];AAA[0][x2][1]=fours[3];AAA[0][x2][2]=sixs[x2];}sixs_maker(fours[0], fours[2], sixs); /*1,3,(0,2)*/for(x2=0; x2<=5; x2++){AAA[1][x2][0]=fours[1];AAA[1][x2][1]=fours[3];AAA[1][x2][2]=sixs[x2];}sixs_maker(fours[0], fours[3], sixs); /*1,2,(0,3)*/for(x2=0; x2<=5; x2++){AAA[2][x2][0]=fours[1];AAA[2][x2][1]=fours[2];AAA[2][x2][2]=sixs[x2];}sixs_maker(fours[1], fours[2], sixs); /*0,3,(1,2)*/for(x2=0; x2<=5; x2++){AAA[3][x2][0]=fours[0];AAA[3][x2][1]=fours[3];AAA[3][x2][2]=sixs[x2];}sixs_maker(fours[1], fours[3], sixs); /*0,2,(1,3)*/for(x2=0; x2<=5; x2++){AAA[4][x2][0]=fours[0];AAA[4][x2][1]=fours[2];AAA[4][x2][2]=sixs[x2];}sixs_maker(fours[2], fours[3], sixs); /*0,1,(2,3)*/for(x2=0; x2<=5; x2++){AAA[5][x2][0]=fours[0];AAA[5][x2][1]=fours[1];AAA[5][x2][2]=sixs[x2];}}void BBB_maker(float AAA[6][6][3], float BBB[6][6][3][6][2], int x1, int x2) /*BBB存储的第二步运算结果*/{int x4;float sixs[6], threes[3];threes[0]=AAA[x1][x2][0];threes[1]=AAA[x1][x2][1];threes[2]=AAA[x1][x2][2];sixs_maker(threes[0], threes[1], sixs); /*2,(0,1)*/for(x4=0; x4<=5; x4++){BBB[x1][x2][0][x4][0]=threes[2];BBB[x1][x2][0][x4][1]=sixs[x4];}sixs_maker(threes[0], threes[2], sixs); /*1,(0,2)*/for(x4=0; x4<=5; x4++){BBB[x1][x2][1][x4][0]=threes[1];BBB[x1][x2][1][x4][1]=sixs[x4];}sixs_maker(threes[1], threes[2], sixs); /*0,(1,2)*/for(x4=0; x4<=5; x4++){BBB[x1][x2][2][x4][0]=threes[0];BBB[x1][x2][2][x4][1]=sixs[x4];}}void CCC_maker(float BBB[6][6][3][6][2], float CCC[6][6][3][6][6], int x1, int x2, int x3, int x4, int dingwei[6], int Tezhengzhi) /*CCC存储的第三步运算结果*/ {int x5;float sixs[6];sixs_maker(BBB[x1][x2][x3][x4][0], BBB[x1][x2][x3][x4][1], sixs);for(x5=0; x5<=5; x5++){CCC[x1][x2][x3][x4][x5]=sixs[x5];if(sixs[x5]<Tezhengzhi+0.0001 && sixs[x5]>Tezhengzhi-0.0001) /*运算成功*/{dingwei[0]=x1;dingwei[1]=x2;dingwei[2]=x3;dingwei[3]=x4;dingwei[4]=x5;dingwei[5]=1;return;}}}void myprint(int xuhao, int* jishu, float fours[4], int dingwei[6], FILE *fp) {char a0[3], a1[3], a2[3], a3[3];char s0[20], s1[20], s2[20], s3[20], t[20];if(dingwei[5]!=1){fprintf(fp, "%5d.\tNO\t\t%3d,%3d,%3d,%3d\n", xuhao, (int)fours[0], (int)fours[1], (int)fours[2], (int)fours[3]);return;}fprintf(fp, "%5d.\tYes\t\t%3d,%3d,%3d,%3d", xuhao, (int)fours[0],(int)fours[1], (int)fours[2], (int)fours[3]);(*jishu)++;sprintf(a0, "%d", (int)(fours[0]));sprintf(a1, "%d", (int)(fours[1]));sprintf(a2, "%d", (int)(fours[2]));sprintf(a3, "%d", (int)(fours[3]));switch (dingwei[0]){case0: {strcpy(s0, a2);strcpy(s1, a3);strcpy(s2, a0);strcpy(s3, a1);break;}case1: {strcpy(s0, a1);strcpy(s1, a3);strcpy(s2, a0);strcpy(s3, a2);break;}case2: {strcpy(s0, a1);strcpy(s1, a2);strcpy(s2, a0);strcpy(s3, a3);break;}case3: {strcpy(s0, a0);strcpy(s1, a3);strcpy(s2, a1);strcpy(s3, a2);break;}case4: {strcpy(s0, a0);strcpy(s1, a2);strcpy(s2, a1);strcpy(s3, a3);break;}case5: {strcpy(s0, a0);strcpy(s1, a1);strcpy(s2, a2);strcpy(s3, a3);break;}}switch (dingwei[1]){case0:{strcat(s2, "+");strcat(s2, s3);break;}case1:{strcat(s2, "-");strcat(s2, s3);break;}case2:{strcat(s3, "-");strcat(s3, s2);strcpy(s2, s3);break;}case3:{strcat(s2, "*");strcat(s2, s3);break;}case4:{strcat(s2, "/");strcat(s2, s3);break;}case5:{strcat(s3, "/");strcat(s3, s2);strcpy(s2, s3);break;} }strcpy(s3, "(");strcat(s3, s2);strcat(s3, ")");strcpy(s2, s3);switch (dingwei[2]){case0:{strcpy(t, s0);strcpy(s0, s1);strcpy(s1, t);strcpy(t,s0);strcpy(s0, s2);strcpy(s2, t);break;}case1:{strcpy(t, s0);strcpy(s0, s1);strcpy(s1, t);break;}case2:break;}switch (dingwei[3]){case0:{strcat(s1, "+");strcat(s1, s2);break;}case1:{strcat(s1, "-");strcat(s1, s2);break;}case2:{strcat(s2, "-");strcat(s2, s1);strcpy(s1, s2);break;}case3:{strcat(s1, "*");strcat(s1, s2);break;}case4:{strcat(s1, "/");strcat(s1, s2);break;}case5:{strcat(s2, "/");strcat(s2, s1);strcpy(s1, s2);break;} }strcpy(s3, "(");strcat(s3, s1);strcat(s3, ")");strcpy(s1, s3);switch (dingwei[4]){case0:{strcat(s0, "+");strcat(s0, s1);break;}case1:{strcat(s0, "-");strcat(s0, s1);break;}case2:{strcat(s1, "-");strcat(s1, s0);strcpy(s0, s1);break;}case3:{strcat(s0, "*");strcat(s0, s1);break;}case4:{strcat(s0, "/");strcat(s0, s1);break;}case5:{strcat(s1, "/");strcat(s1, s0);strcpy(s0, s1);break;} }。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include"../ucos-ii/includes.h"#include "../ucos-ii/add/osaddition.h"#include "../inc/drivers.h"#include "../ucos-ii/add/Ustring.h"#include "../ucos-ii/add/Osmessage.h"#include "../inc/sys/lib.h"#include "../src/gui/gui.h"#include "../inc/RTC.h" //New#include <string.h>#include <stdio.h>#include <stdlib.h>/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <math.h>#define MAX 50char strs[];char output[MAX] ;char stack[MAX] ;char input[MAX];char *s, *t ; /*pointers to input and output strings*/ char ch; /*choice*/int top; /*Stack top*/int l ; /*length of infix string*/int morless[]; /* more or less than 10 */int inputtimes; /*input times */int khtemp;/*kuo hao */int strLength;int istack[MAX];int iposition;/*Function Prototypes*/void Initialize (void);void SetExpression (char *);char PopFromStack (void );void PushOnStack (char);int priority (char);void ConvertToPostfix (void);void SetOutput();void fun();void fun2();void Cal();struct s_node{int data;struct s_node *next;};typedef struct s_node s_list;typedef s_list *link;void ipush(int i);int ipop();void Time(void *Id);void ShowChu();/* 定义一个大小为4的字符型数组*/char sig[4]={'+','-','*','/'};float num[4];int Ltemp;int k;int i;int j;char cx[4][50];int dif;int cj; //出题或者解题int game;U16* ptext;float get[4];int scori;//成绩int rad;int um[4];int m[4];int id;int tempr ;int timeover;int flag;int cc24;char cfch;structTime pstrctTime;//***************************显示答案正确**********************// PTextCtrl pwonderful;structRECT wrect;U16 wstr[]={0x6b63,0x786e,0x002c,0x771f,0x68d2,0x0021,0x0000};//wonderfulU16 fstr[]={0x8ba1,0x7b97,0x9519,0x8bef,0x0000};//fail///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////OS_STK Main_Stack[STACKSIZE]={0, }; //Main_Test_Task堆栈void Main_Task(void *Id); //Main_Test_Task#define Main_Task_Prio 12///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////int main(void){ARMTargetInit(); // do target (uHAL based ARM system) initialisation //OSInit(); // needed by uC/OS-II //OSInitUart();initOSFile();initOSMessage();initOSList();initOSDC();initOSCtrl();LoadFont();InitRtc();loadsystemParam();LCD_printf("Create task on uCOS-II...\n");OSTaskCreate(Main_Task, (void *)0, (OS_STK *)&Main_Stack[STACKSIZE-1], Main_Task_Prio);OSAddTask_Init(1);LCD_printf("Starting uCOS-II...\n");LCD_printf("Entering graph mode...\n");LCD_ChangeMode(DspGraMode);OSStart(); // 开始任务调度//// never reached //return 0;}////////////////////////////////////////////////////////////////////////////////#define ID_ButtonOut 99#define ID_ButtonIn 100#define ID_ButtonNum1 101#define ID_ButtonNum2 102#define ID_ButtonNum3 103#define ID_ButtonNum4 104#define ID_ButtonNum5 105#define ID_ButtonNum6 106#define ID_ButtonNum7 107#define ID_ButtonNum8 108#define ID_ButtonNum9 109#define ID_ButtonNum10 110#define ID_ButtonNum11 111#define ID_ButtonNum12 112#define ID_ButtonNum13 113#define ID_ButtonAdd 114#define ID_ButtonSub 115#define ID_ButtonMul 116#define ID_ButtonDiv 117#define ID_ButtonLpar 118#define ID_ButtonRpar 119#define ID_ButtonOk 120#define ID_ButtonOk2 123#define ID_ButtonCancel 121#define ID_ButtonNo 122U16 astr[]={0x60a8,0x7684,0x7b54,0x6848,0x662f,0x003a}; //您的答案是U16 pstr[]={0x8bf7,0x9009,0x62e9,0x0034,0x4e2a,0x6570,0x0000}; //请选择4个数U16 nstr[]={0x65e0,0x89e3,0x0000};//无解U16 cstr[]={0x6b63,0x786e,0x7b54,0x6848,0x662f};//正确答案是U16 string[]={0x8bf7,0x7ec4,0x6210,0x8868,0x8fbe,0x5f0f,0x0000};//请组成表达式U16 restring[]={0x8bf7,0x91cd,0x65b0,0x8f93,0x5165,0x0000};//请重新输入U16 Num1ButtonCaption[3]={0x0031,0x0000,0x0000};U16 Num2ButtonCaption[3]={0x0032,0x0000,0x0000};U16 Num3ButtonCaption[3]={0x0033,0x0000,0x0000};U16 Num4ButtonCaption[3]={0x0034,0x0000,0x0000};U16 Num5ButtonCaption[3]={0x0035,0x0000,0x0000};U16 Num6ButtonCaption[3]={0x0036,0x0000,0x0000};U16 Num7ButtonCaption[3]={0x0037,0x0000,0x0000};U16 Num8ButtonCaption[3]={0x0038,0x0000,0x0000};U16 Num9ButtonCaption[3]={0x0039,0x0000,0x0000};U16 Num10ButtonCaption[3]={0x0031,0x0030,0x0000};U16 Num11ButtonCaption[3]={0x0031,0x0031,0x0000};U16 Num12ButtonCaption[3]={0x0031,0x0032,0x0000};U16 Num13ButtonCaption[3]={0x0031,0x0033,0x0000};U16 AddButtonCaption[3]={0x002b,0x0000,0x0000};U16 SubButtonCaption[3]={0x002d,0x0000,0x0000};U16 MulButtonCaption[3]={0x0078,0x0000,0x0000};U16 DivButtonCaption[3]={0x002f,0x0000,0x0000};U16 LparButtonCaption[3]={0x0028,0x0000,0x0000};U16 RparButtonCaption[3]={0x0029,0x0000,0x0000};U16 NoButtonCaption[3]={0x65e0,0x89e3,0x0000};U16 OkButtonCaption[3]={0x786e,0x5b9a,0x0000};//确定//////{0x5f00,0x59cb,0x0000};//开始U16 CancelButtonCaption[3]={0x9000,0x683c,0x0000};U16 OutButtonCaption[5]={0x6211,0x8981,0x51fa,0x9898,0x0000};U16 InButtonCaption[5]={0x6211,0x8981,0x8ba1,0x7b97,0x0000};PButtonCtrl pNum1Button;PButtonCtrl pNum2Button;PButtonCtrl pNum3Button;PButtonCtrl pNum4Button;PButtonCtrl pNum5Button;PButtonCtrl pNum6Button;PButtonCtrl pNum7Button;PButtonCtrl pNum8Button;PButtonCtrl pNum9Button;PButtonCtrl pNum10Button;PButtonCtrl pNum11Button;PButtonCtrl pNum12Button;PButtonCtrl pNum13Button;PButtonCtrl pAddButton;PButtonCtrl pSubButton;PButtonCtrl pMulButton;PButtonCtrl pDivButton;PButtonCtrl pLparButton;PButtonCtrl pRparButton;PButtonCtrl pNoButton;PButtonCtrl pOkButton;PButtonCtrl pOk2Button;PButtonCtrl pCancelButton;structRECT Num1ButtonRect;structRECT Num2ButtonRect;structRECT Num3ButtonRect;structRECT Num4ButtonRect;structRECT Num5ButtonRect;structRECT Num6ButtonRect;structRECT Num7ButtonRect;structRECT Num8ButtonRect;structRECT Num9ButtonRect;structRECT Num10ButtonRect;structRECT Num11ButtonRect;structRECT Num12ButtonRect;structRECT Num13ButtonRect;structRECT AddButtonRect;structRECT SubButtonRect;structRECT MulButtonRect;structRECT DivButtonRect;structRECT LparButtonRect;structRECT RparButtonRect;structRECT NoButtonRect;structRECT OkButtonRect;structRECT Ok2ButtonRect;structRECT CancelButtonRect;structRECT NumaButtonRect;structRECT NumbButtonRect;structRECT NumcButtonRect;structRECT NumdButtonRect;/***************************显示匡*******************************/ structRECT rect;structRECT Trect;PTextCtrl pTextCtrl;PTextCtrl tTextCtrl;#define ID_MainTextCtrl 98#define ID_TimeTextCtrl 97/***************************开始界面*****************************/ PButtonCtrl pOutButton;PButtonCtrl pInButton;structRECT OutButtonRect;structRECT InButtonRect;structRECT PicBmpRect;/*******************************计分部分***************************/ #define ID_SCaption 200#define ID_ScoreText 201PTextCtrl pScore;PTextCtrl pSCaption;structRECT ScoreRect;structRECT SCRect;#define ID_wonderText 203OS_EVENT *Rtc_Updata_Sem; //时钟更新控制权OS_STK Rtc_Disp_Stack[STACKSIZE]={0, }; //Rtc_Disp_Task堆栈void Rtc_Disp_Task(void *Id); //Rtc_Disp_Task#define Rtc_Disp_Task_Prio 62/********************************??*****************************////////////////////////////////////////////////////////////////////////////////void Main_Task(void *Id) //主任务,负责键盘的扫描{POSMSG pMsg;/************************showtext************************************/ PDC pdc;Uart_Printf(0,"begin Main task \n");SetRect(&OutButtonRect,50,190,130,220);SetRect(&InButtonRect,190,190,270,220);xunhuan:LCD_Cls();LCD_ChangeMode(DspGraMode);pdc=CreateDC();pOutButton=CreateButton(ID_ButtonOut,&OutButtonRect,FONTSIZE_MIDDLE,3,OutButt onCaption,NULL);DrawButton(pOutButton);pInButton=CreateButton(ID_ButtonIn,&InButtonRect,FONTSIZE_MIDDLE,3,InButtonCap tion,NULL);DrawButton(pInButton);if(scori>=0&&scori<10)dif=1;if(scori>=10&&scori<20)dif=2;if(scori>=20&&scori<30)dif=3;if(scori>30)dif=4;Score();for(;;){POS_Ctrl pCtrl;pMsg=WaitMessage(0);if(pMsg->pOSCtrl){if(pMsg->pOSCtrl->CtrlMsgCallBk)(*pMsg->pOSCtrl->CtrlMsgCallBk)(pMsg);}else{switch(pMsg->Message){case OSM_BUTTON_CLICK:switch(pMsg->WParam){case ID_ButtonOut:ClearScreen();LCD_Refresh();DestoryDC(pdc);DestoryButton(pOutButton);Out();DeleteMessage(pMsg);goto xunhuan;break;case ID_ButtonIn:ClearScreen();LCD_Refresh();DestoryDC(pdc);DestoryButton(pInButton);In();DeleteMessage(pMsg);goto xunhuan;break;}default:OSOnSysMessage(pMsg);break;}}DeleteMessage(pMsg);OSTimeDly(200);}}Out() //人出题,电脑做题{POSMSG pMsg;/************************showtext************************************/ PDC pdc;pdc=CreateDC();k=0;SetRect(&rect, 40,80,520,120); //设置文本框pTextCtrl=CreateTextCtrl(ID_MainTextCtrl, &rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME,NULL,NULL); //pTextCtrl=CreateTextCtrl(ID_MainTextCtrl, &rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME,ShowTable,NULL);SetWndCtrlFocus(NULL, ID_MainTextCtrl);DrawTextCtrl(pTextCtrl);SetRect(&OkButtonRect,340,400,420,440);pOkButton=CreateButton(ID_ButtonOk,&OkButtonRect,FONTSIZE_MIDDLE,CTRL_STY LE_FRAME,OkButtonCaption,NULL);DrawButton(pOkButton);/**************************开始数字****************************/SetRect(&Num1ButtonRect,40,160,120,200);SetRect(&Num2ButtonRect,140,160,220,200);SetRect(&Num3ButtonRect,240,160,320,200);SetRect(&Num4ButtonRect,320,160,420,200);SetRect(&Num5ButtonRect,440,160,520,200);SetRect(&Num6ButtonRect,40,220,120,260);SetRect(&Num7ButtonRect,140,220,220,260);SetRect(&Num8ButtonRect,240,220,320,260);SetRect(&Num9ButtonRect,340,220,420,260);SetRect(&Num10ButtonRect,440,220,520,260);/***********************Num10~~13可改动*************************/ SetRect(&Num11ButtonRect,40,280,120,320);SetRect(&Num12ButtonRect,140,280,220,320);SetRect(&Num13ButtonRect,240,280,320,320);if(pNum1Button!=NULL){DestoryButton(pNum1Button);}if(pNum2Button!=NULL){DestoryButton(pNum2Button);}if(pNum3Button!=NULL){DestoryButton(pNum3Button);}if(pNum4Button!=NULL){DestoryButton(pNum4Button);}if(pNum5Button!=NULL){DestoryButton(pNum5Button);}if(pNum6Button!=NULL){DestoryButton(pNum6Button);}if(pNum7Button!=NULL){DestoryButton(pNum7Button);}if(pNum8Button!=NULL){DestoryButton(pNum8Button);}if(pNum9Button!=NULL){DestoryButton(pNum9Button);}if(pNum10Button!=NULL){DestoryButton(pNum10Button);}if(pNum11Button!=NULL){DestoryButton(pNum11Button);}if(pNum12Button!=NULL){DestoryButton(pNum12Button);}if(pNum13Button!=NULL){DestoryButton(pNum13Button);}pNum1Button=CreateButton(ID_ButtonNum1,&Num1ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num1ButtonCaption,NULL);DrawButton(pNum1Button);pNum2Button=CreateButton(ID_ButtonNum2,&Num2ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num2ButtonCaption,NULL);DrawButton(pNum2Button);pNum3Button=CreateButton(ID_ButtonNum3,&Num3ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num3ButtonCaption,NULL);DrawButton(pNum3Button);pNum4Button=CreateButton(ID_ButtonNum4,&Num4ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num4ButtonCaption,NULL);DrawButton(pNum4Button);pNum5Button=CreateButton(ID_ButtonNum5,&Num5ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num5ButtonCaption,NULL);DrawButton(pNum5Button);pNum6Button=CreateButton(ID_ButtonNum6,&Num6ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num6ButtonCaption,NULL);DrawButton(pNum6Button);pNum7Button=CreateButton(ID_ButtonNum7,&Num7ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num7ButtonCaption,NULL);DrawButton(pNum7Button);pNum8Button=CreateButton(ID_ButtonNum8,&Num8ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num8ButtonCaption,NULL);DrawButton(pNum8Button);pNum9Button=CreateButton(ID_ButtonNum9,&Num9ButtonRect,FONTSIZE_MIDDLE,C TRL_STYLE_FRAME,Num9ButtonCaption,NULL);DrawButton(pNum9Button);pNum10Button=CreateButton(ID_ButtonNum10,&Num10ButtonRect,FONTSIZE_MIDDL E,CTRL_STYLE_FRAME,Num10ButtonCaption,NULL);DrawButton(pNum10Button);//******************************11~~13***************************************** ****//if(dif>1){pNum11Button=CreateButton(ID_ButtonNum11,&Num11ButtonRect,FONTSIZE_MIDDL E,CTRL_STYLE_FRAME,Num11ButtonCaption,NULL);DrawButton(pNum11Button);}if(dif>2){pNum12Button=CreateButton(ID_ButtonNum12,&Num12ButtonRect,FONTSIZE_MIDDL E,CTRL_STYLE_FRAME,Num12ButtonCaption,NULL);DrawButton(pNum12Button);}if(dif>3){pNum13Button=CreateButton(ID_ButtonNum13,&Num13ButtonRect,FONTSIZE_MIDDL E,CTRL_STYLE_FRAME,Num13ButtonCaption,NULL);DrawButton(pNum13Button);}SetTextCtrlText(pTextCtrl, pstr,TRUE);// 请选择4个数DestoryDC(pdc);Score();for(;;){POS_Ctrl pCtrl;pMsg=WaitMessage(0);if(pMsg->pOSCtrl){if(pMsg->pOSCtrl->CtrlMsgCallBk)(*pMsg->pOSCtrl->CtrlMsgCallBk)(pMsg);}else{switch(pMsg->Message){case OSM_BUTTON_CLICK:switch(pMsg->WParam){case ID_ButtonOk:{//判断是否为4个数,调用Cal_24计算//ClearScreen();LCD_Refresh();DestoryDC(pdc);DestoryButton(pOkButton);Cal_24();DeleteMessage(pMsg);return;}case ID_ButtonNum1:if (k<4){AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 1;Uart_Printf(0,"1");k++;}break;case ID_ButtonNum2:if (k<4){AppendChar2TextCtrl(pTextCtrl,'2',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 2;Uart_Printf(0,"2");k++;}break;case ID_ButtonNum3:if (k<4){AppendChar2TextCtrl(pTextCtrl,'3',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 3;Uart_Printf(0,"3");k++;}break;case ID_ButtonNum4:if (k<4){AppendChar2TextCtrl(pTextCtrl,'4',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 4;Uart_Printf(0,"4");k++;}break;case ID_ButtonNum5:if (k<4){AppendChar2TextCtrl(pTextCtrl,'5',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 5;Uart_Printf(0,"5");k++;}break;case ID_ButtonNum6:if (k<4){AppendChar2TextCtrl(pTextCtrl,'6',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 6;Uart_Printf(0,"6");k++;}break;case ID_ButtonNum7:if (k<4){AppendChar2TextCtrl(pTextCtrl,'7',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 7;Uart_Printf(0,"7");k++;}break;case ID_ButtonNum8:if (k<4){AppendChar2TextCtrl(pTextCtrl,'8',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 8;Uart_Printf(0,"8");k++;}break;case ID_ButtonNum9:if (k<4){AppendChar2TextCtrl(pTextCtrl,'9',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 9;Uart_Printf(0,"9");k++;}break;case ID_ButtonNum10:if (k<4){AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'0',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 10;Uart_Printf(0,"10");k++;}break;case ID_ButtonNum11:if (k<4){AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 11;Uart_Printf(0,"11");k++;}break;case ID_ButtonNum12:if (k<4){AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'2',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 12;k++;}break;case ID_ButtonNum13:if (k<4){AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'3',TRUE);AppendChar2TextCtrl(pTextCtrl,' ',TRUE);get[k]= 13;k++;}break;}default:OSOnSysMessage(pMsg);break;}}DeleteMessage(pMsg);OSTimeDly(200);}}//********************************************************************// int Cal_24(){PDC pdc;float num[4];int i;char cx[4][50];pdc=CreateDC();Ltemp=0;/* 得到输入,保存在浮点数组num里面*/for(i = 0; i < 4; i ++){num[i] = get[i];Uart_Printf(0,"%f",get[i]);}/* 将num的值变成字符串的形式.为了给出最后的表达式*/for(i = 0; i < 4; i ++){sprintf(cx[i], "%d", (int)num[i]);/* 运行函数,将得到的参数传递过去*/LCD_ChangeMode(DspTxtMode);fun(num, cx, 4);if(Ltemp!=1){SetRect(&wrect,140,60,240,130);pwonderful=CreateTextCtrl(ID_wonderText,&wrect,FONTSIZE_MIDDLE,CTRL_STYLE_ NOFRAME,NULL,NULL);SetTextCtrlText(pwonderful,nstr,TRUE);Uart_Printf(0,"no answer");}DestoryDC(pdc);OSTimeDly(5000);}/* 定义函数.根据给定的内容计算24点.参数为浮点型数组(每个值),字符型数组(表达式),和整数(使用多少个数计算24点) */void fun(float n[],char ch[][50],int m){int loop1, loop2, y, i, j;float num[4];char cc[4][50];if(m == 1){/* 如果n[0] - 24.0的绝对值小于0.0001,就认为他们相等.显示表达式的内容.退出*/if(fabs(n[0] - 24.0) < 0.0001){Uart_Printf(0,"\nexpress:%s = 24\n",ch[0]);LCD_printf("\nexpress:%s = 24\n",ch[0]);OSTimeDly(600);Ltemp=1;return;}}else{for(loop1 = 0; loop1 < m; loop1 ++)for(loop2 = 0; loop2 < m; loop2 ++){/* 如果loop2 = loop1,进入下轮循环(同一个数不能使用两次,因为使用n[loop]来进行运算) */if(loop2 == loop1)continue;for(y = 0; y < 4; y ++){switch(y) /* 检查y的值,和那个相符就执行case那个的子句*/{case 0: num[0] = n[loop1] + n[loop2];break;case 1: num[0] = n[loop1] - n[loop2];break;case 2: num[0] = n[loop1] * n[loop2];break;case 3: if(n[loop2] == 0) /* 除数为0,break; */break;num[0] = n[loop1] / n[loop2];break;default:break;}if(y != 3 || n[loop2] != 0) /* 除数为零的除法以外的操作,将表达式的内容存入cc[0]里面*/sprintf(cc[0],"(%s%c%s)",ch[loop1],sig[y],ch[loop2]);for(i = 0,j = 1; i < m; i ++){if(i != loop1 && i != loop2){num[j] = n[i];/* 字符串copy,将ch[i]的内容放入cc[j]里面*/strcpy(cc[j], ch[i]);j ++;}}/* 递归调用*/fun(num, cc, m - 1);}}}}//***************************************************************************** ***************//In() //电脑出题人做题{int inputi ;POSMSG pMsg;ClearScreen();flag=0;Score();for(inputi = 0 ; inputi < MAX; inputi ++){input[inputi] = '\0';}if(dif ==1){radom10();ShowChu();}else if(dif ==2){radom11();ShowChu();}else if(dif ==3){radom12();ShowChu();}else if(dif ==4){radom13();ShowChu();}/****************************************************************************** **********/for(;;){POS_Ctrl pCtrl;pMsg=WaitMessage(0);inputtimes = 0;khtemp =0;if(pMsg->pOSCtrl){if(pMsg->pOSCtrl->CtrlMsgCallBk)(*pMsg->pOSCtrl->CtrlMsgCallBk)(pMsg);}else{switch(pMsg->Message){case OSM_BUTTON_CLICK:if(tempr==1){pTextCtrl->text[0]=0; //清空文本框tempr=0;}switch(pMsg->WParam){case ID_ButtonLpar:{AppendChar2TextCtrl(pTextCtrl,'(',TRUE);strcat(input,"(");khtemp++;morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonRpar:{AppendChar2TextCtrl(pTextCtrl,')',TRUE);strcat(input,")");khtemp--;morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonAdd:{AppendChar2TextCtrl(pTextCtrl,'+',TRUE);strcat(input,"+");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonSub:{AppendChar2TextCtrl(pTextCtrl,'-',TRUE);strcat(input,"-");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonMul:{AppendChar2TextCtrl(pTextCtrl,'*',TRUE);strcat(input,"*");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonDiv:{AppendChar2TextCtrl(pTextCtrl,'/',TRUE);strcat(input,"/");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonCancel:{TextCtrlDeleteChar(pTextCtrl,TRUE);//退格//strLength = strlen(input);if(morless[inputtimes] == 0){TextCtrlDeleteChar(pTextCtrl,TRUE);//退格//input[strLength -1] = '\0';}else if(morless[inputtimes] == 1){TextCtrlDeleteChar(pTextCtrl,TRUE);//退格//TextCtrlDeleteChar(pTextCtrl,TRUE);//退格//input[strLength -5] = '\0';inputtimes --;}break;/***************************************times响应*********************************/case 300:{PDC pdc;pdc=CreateDC();Uart_Printf(0,"300");LCD_Cls();ClearScreen();LCD_printf("time over");OSTimeDly(1000);DestoryDC(pdc);flag=1;}if(flag==1){OSTaskDel( Rtc_Disp_Task_Prio);//删除任务}break;/****************************************************************************** ****/case ID_ButtonOk:{Uart_Printf(0,"%i,%i",khtemp,inputtimes);if(khtemp == 0){DeleteMessage(pMsg);Cal();return;}else{pTextCtrl->text[0]=0; //清空文本框SetTextCtrlText(pTextCtrl,restring,TRUE);//请重新输入inputtimes=0;input[0]=NULL;}DestoryButton(pOkButton);}break;case ID_ButtonNum1:{AppendChar2TextCtrl(pTextCtrl,'1',TRUE);strcat(input,"1");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum2:{AppendChar2TextCtrl(pTextCtrl,'2',TRUE);strcat(input,"2");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum3:{AppendChar2TextCtrl(pTextCtrl,'3',TRUE);strcat(input,"3");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum4:{AppendChar2TextCtrl(pTextCtrl,'4',TRUE);strcat(input,"4");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum5:{AppendChar2TextCtrl(pTextCtrl,'5',TRUE);strcat(input,"5");morless[inputtimes] = 0;inputtimes ++;break;case ID_ButtonNum6:{AppendChar2TextCtrl(pTextCtrl,'6',TRUE);strcat(input,"6");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum7:{AppendChar2TextCtrl(pTextCtrl,'7',TRUE);strcat(input,"7");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum8:{AppendChar2TextCtrl(pTextCtrl,'8',TRUE);strcat(input,"8");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum9:{AppendChar2TextCtrl(pTextCtrl,'9',TRUE);strcat(input,"9");morless[inputtimes] = 0;inputtimes ++;}break;case ID_ButtonNum10:{AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'0',TRUE);strcat(input,"(1+9)");morless[inputtimes] = 1;inputtimes ++;}break;case ID_ButtonNum11:AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'1',TRUE);strcat(input,"(2+9)");morless[inputtimes] = 1;inputtimes ++;}break;case ID_ButtonNum12:{AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'2',TRUE);strcat(input,"(3+9)");morless[inputtimes] = 1;inputtimes ++;}break;case ID_ButtonNum13:{AppendChar2TextCtrl(pTextCtrl,'1',TRUE);AppendChar2TextCtrl(pTextCtrl,'3',TRUE);strcat(input,"(4+9)");morless[inputtimes] = 1;inputtimes ++;}break;}default:OSOnSysMessage(pMsg);break;}}DeleteMessage(pMsg);OSTimeDly(200);}}/****************************************************************************** *************/void ShowChu(){PDC pdc;pdc=CreateDC();SetRect(&rect, 40,80,520,120); //设置文本框pTextCtrl=CreateTextCtrl(ID_MainTextCtrl, &rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME,NULL,NULL); //pTextCtrl=CreateTextCtrl(ID_MainTextCtrl, &rect, FONTSIZE_MIDDLE, CTRL_STYLE_FRAME,ShowTable,NULL);SetWndCtrlFocus(NULL, ID_MainTextCtrl);DrawTextCtrl(pTextCtrl);/************************从这里设置难? 出题或解?************************/ game = 1;/************************开始符号**********************************/SetRect(&LparButtonRect,340,280,420,320);SetRect(&RparButtonRect,440,280,520,320);SetRect(&AddButtonRect,40,340,120,380);SetRect(&SubButtonRect,140,340,220,380);SetRect(&MulButtonRect,240,340,320,380);SetRect(&DivButtonRect,340,340,420,380);SetRect(&NoButtonRect,240,400,320,440);SetRect(&OkButtonRect,340,400,420,440);SetRect(&CancelButtonRect,440,400,520,440);if(pNum1Button!=NULL){DestoryButton(pNum1Button);}if(pNum2Button!=NULL){DestoryButton(pNum2Button);}if(pNum3Button!=NULL){DestoryButton(pNum3Button);}if(pNum4Button!=NULL){DestoryButton(pNum4Button);}if(pNum5Button!=NULL){DestoryButton(pNum5Button);}if(pNum6Button!=NULL){DestoryButton(pNum6Button);}if(pNum7Button!=NULL){DestoryButton(pNum7Button);}if(pNum8Button!=NULL){DestoryButton(pNum8Button); }if(pNum9Button!=NULL){DestoryButton(pNum9Button); }if(pNum10Button!=NULL){DestoryButton(pNum10Button); }if(pNum11Button!=NULL){DestoryButton(pNum11Button); }if(pNum12Button!=NULL){DestoryButton(pNum12Button); }if(pNum13Button!=NULL){DestoryButton(pNum13Button);}if(pLparButton!=NULL){DestoryButton(pLparButton);}if(pRparButton!=NULL){DestoryButton(pRparButton);}if(pAddButton!=NULL){DestoryButton(pAddButton);}if(pDivButton!=NULL){DestoryButton(pDivButton);}if(pMulButton!=NULL){DestoryButton(pMulButton);}if(pSubButton!=NULL){DestoryButton(pSubButton);}if(pCancelButton!=NULL){DestoryButton(pCancelButton);}//*******************************符号sign******************************************//pLparButton=CreateButton(ID_ButtonLpar,&LparButtonRect,FONTSIZE_MIDDLE,CTRL _STYLE_FRAME,LparButtonCaption,NULL);DrawButton(pLparButton);pRparButton=CreateButton(ID_ButtonRpar,&RparButtonRect,FONTSIZE_MIDDLE,CTRL _STYLE_FRAME,RparButtonCaption,NULL);DrawButton(pRparButton);。

相关文档
最新文档