资源简介
实现了24点游戏的算法,只需输入4个数字就可以打印有多少种算出24点的方法

代码片段和文件信息
//////////////////////////////////////////////////////////////////////////
// 编程题目: 计算 24 点
// 编译环境: Visual C++ 6.0
// 程序设计: 廖增祥
//////////////////////////////////////////////////////////////////////////
#include
//////////////////////////////////////////////////////////////////////////
// Process: 计算处理过程 递归函数
// result [in] 当前计算结果
// a [in] 原始计算数据
// fuhao [in out] 要保存的符号数组
// nIndex [in] 当前递归所在层[0 - 2]
int Process(int result int *a char *fuhao int nIndex)
{
int temp;
// 1. 计算加法
temp = result + a[nIndex + 1];
fuhao[nIndex] = ‘+‘;
if(temp == 24 && nIndex == 2)
return 1;
if(nIndex < 2)
if(Process(temp a fuhao nIndex + 1))
return 1;
// 2. 计算减法
temp = result - a[nIndex + 1];
fuhao[nIndex] = ‘-‘;
if(temp == 24 && nIndex == 2)
return 1;
if(nIndex < 2)
if(Process(temp a fuhao nIndex + 1))
return 1;
// 3. 计算乘法
temp = result * a[nIndex + 1];
fuhao[nIndex] = ‘*‘;
if(nIndex != 0)
{
// 重新计算 temp 的值
if(fuhao[nIndex - 1] == ‘+‘)
{
temp = result - a[nIndex] + a[nIndex] * a[nIndex + 1];
}
else if(nIndex == 2 && fuhao[0] == ‘+‘ && (fuhao[1] == ‘*‘ || fuhao[1] == ‘/‘))
{
temp = result - (result - a[0]) + (result - a[0]) * a[nIndex + 1];
}
else if(fuhao[nIndex - 1] == ‘-‘)
{
temp = result + a[nIndex] - a[nIndex] * a[nIndex + 1];
}
else if(nIndex == 2 && fuhao[0] == ‘-‘ && (fuhao[1] == ‘*‘ || fuhao[1] == ‘/‘))
{
temp = result + (result - a[0]) - (result - a[0]) * a[nIndex + 1];
}
}
if(temp == 24 && nIndex == 2)
return 1;
if(nIndex < 2)
if(Process(temp a fuhao nIndex + 1))
return 1;
// 4. 计算除法
int bContinue = 1;
if(a[nIndex + 1] == 0)
return 0;
temp = result / a[nIndex + 1];
fuhao[nIndex] = ‘/‘;
if(nIndex != 0)
{
if(fuhao[nIndex - 1] == ‘+‘)
{
// 重新计算 temp 的值
if(a[nIndex + 1] && a[nIndex] % a[nIndex + 1] == 0)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-11-08 01:56 24point\
文件 5514 2013-11-07 01:50 24point\24point.cpp
文件 4296 2013-11-07 02:06 24point\24point.dsp
文件 520 2013-11-06 23:13 24point\24point.dsw
文件 41984 2013-11-08 01:55 24point\24point.ncb
文件 48640 2013-11-08 01:55 24point\24point.opt
文件 893 2013-11-07 01:50 24point\24point.plg
目录 0 2013-11-07 01:50 24point\Debug\
文件 184389 2013-11-07 01:50 24point\Debug\24point.exe
文件 215180 2013-11-07 01:50 24point\Debug\24point.ilk
文件 5710 2013-11-07 01:50 24point\Debug\24point.obj
文件 203736 2013-11-06 23:21 24point\Debug\24point.pch
文件 451584 2013-11-07 01:50 24point\Debug\24point.pdb
文件 33792 2013-11-07 01:50 24point\Debug\vc60.idb
文件 45056 2013-11-07 01:50 24point\Debug\vc60.pdb
- 上一篇:辅助防检测--进程隐藏
- 下一篇:[转]易语言|阿里妈妈自动登陆并保持登陆状态
相关资源
- SVR算法程序可运行
- 计算机图形学 边填充算法实现代码
- 福建师范大学历年算法考卷
- 栈的实现及应用,六种基本算法
- Bresenham算法绘制线段并利用“橡皮筋
- 介绍几种压缩算法及《笨笨数据压缩
- 改进的BP神经网络算法
- A星算法_原理讲解_例子
- 云模型的相关算法cloud
- 旋转矩阵求欧拉角的简单算法
- 栅栏填充算法源码(VC)
- RSA算法源码
- 关联分析Apriori算法实现
- [免费]relax算法成像
- 操作系统 LRU算法 实验报告 及 程序代
- 分治法快速排序算法QuickSort C
- 现代谱估计算法 music ESPRIT 谐波分解
- MUSIC算法c 实现
- 007出纳管理系统 v7[1].5.94 算法注册机
- 克鲁斯卡尔算法C和C 实现代码
- capon波束形成算法-VC实现
- QGA 量子遗传算法
- 利用OpenGL写毛笔字算法
- 带头结点的单链表的c算法实现
- 自适应隐写算法wow
- 协同过滤算法源码
- RSA AES DES ECC加密算法源码
- 密码学课程设计:DES加密解密算法的
- 北航人工智能原理课大作业源代码,
- A*算法的2D演示(带源码)
评论
共有 条评论