C++算24点

这篇博客介绍了如何使用C++编程解决算24点的游戏问题。通过算法解析和详细注释,帮助读者理解实现过程。
摘要由CSDN通过智能技术生成

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.
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值