C++算24点
好了,说了呢么多(其实还没说,对吧?),直接贴代码:
/*
Alex
2019.1.30
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cmath>
using namespace std;
/* 存放解集 */
vector<string> ivec;
/* 第1个数和第2个数的值及表达式 */
double key1_2[6] = {
0};
string exp1_2[6];
/* 第3个数和第4个数的值及表达式 */
double key3_4[6] = {
0};
string exp3_4[6];
/* 第3个数和前2个数的值及表达式 */
double key12_3[6] = {
0};
string exp12_3[6];
/* 第4个数和前3个数的值及表达式 */
double key123_4[6] = {
0};
string exp123_4[6];
/* 前2个数和后2个数的值及表达式 */
double key12_34[6] = {
0};
string exp12_34[6];
/* 函数声明 */
int Permutation(int[], int[][4]);
void Calc(double, double, double[], string[], string, string);
void Work(int[], int[][4], int);
/* 主函数 */
int main()
{
int num[4] = {
0};
int array[24][4] = {
0};
int count = 0;
cout << "请输入4个1-13之间的整数,中间以空格隔开" << endl;
/* 读入数据 */
for (int i = 0; i < 4; i++)
{
cin >> num[i];
}
/* 待检测数据的数量 */
count = Permutation(num, array);
/* 求解24点 */
Work(num, array, 24);
/* 对结果进行排序 */
sort(ivec.