###### 一个不错的24点计算程序

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

const double PRECISION = 0.00001;

double number[4];
string expression[4];

bool Search(int n)
{
if (n == 1)
{
if (fabs(number[0] - 24) < PRECISION)
{
cout << expression[0] << endl;
return true;
}
else
{
return false;
}
}

for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
double a, b;
string expa, expb;

a = number[i];
b = number[j];
number[j] = number[n - 1];

expa = expression[i];
expb = expression[j];
expression[j] = expression[n - 1];

expression[i] = '(' + expa + '+' + expb + ')';
number[i] = a + b;
if (Search(n - 1)) return true;

expression[i] = '(' + expa + '-' + expb + ')';
number[i] = a - b;
if (Search(n - 1)) return true;

expression[i] = '(' + expb + '-' + expa + ')';
number[i] = b - a;
if (Search(n - 1)) return true;

expression[i] = '(' + expa + '*' + expb + ')';
number[i] = a * b;
if (Search(n - 1)) return true;

if (b != 0)
{
expression[i] = '(' + expa + '/' + expb + ')';
number[i] = a / b;
if (Search(n - 1)) return true;
}

if (a != 0)
{
expression[i] = '(' + expb + '/' + expa + ')';
number[i] = b / a;
if (Search(n - 1)) return true;
}

number[i] = a;
number[j] = b;
expression[i] = expa;
expression[j] = expb;
}
}
return false;
}

void main()
{
cout <<"Please input four numbers:" <<endl;

for (int i = 0; i < 4; i++)
{
char buffer[20];
int  x;
cin >> x;
number[i] = x;
itoa(x, buffer, 10);
expression[i] = buffer;
}

if (Search(4))
{
cout << "Success." << endl;
}
else
{
cout << "Fail." << endl;
}
}

#### 一个强悍的算24点游戏的PHP程序

2014-04-07 23:15:14

#### 计算24点小程序

2017-04-12 13:08:38

#### 计算24点程序代码

2017-01-24 17:23:48

#### 24点源代码[使用扑克牌显示]

2015-06-16 10:26:41

#### 24点计算程序

2007年09月09日 50KB 下载

#### java经典24点算法代码

2016-11-09 10:06:05

#### 24点问题（穷举法/C++）

2015-07-30 15:04:34

#### 计算24点（python）

2014年12月10日 3KB 下载

#### 纸牌24点，Python程序实现

2017-11-05 13:53:59

#### C++实现24点游戏算法

2015-09-24 11:39:11