摘要:
增加了部分去重复的功能,以及后缀转中缀显示。#include <iostream>
#include <stack>
#include <algorithm>
#include <string>
#include <cmath>
#include <time.h>
using namespace std; struct TOperData
{ int operType; double data;
}; //检查计算的参数是否合法,也可以用于过滤一些重复的表达式
bool checkjisuan(double a, doub 阅读全文
摘要:
前面既然确定了后缀表达式的序列。那就可以开始遍历了。#include <iostream>
#include <stack>
#include <algorithm>
#include <string>
#include <cmath>
#include <time.h>
using namespace std; struct TOperData
{ int operType; double data;
}; //检查计算的参数是否合法,也可以用于过滤一些重复的表达式
bool checkjisuan(double a, 阅读全文
摘要:
无意间看见这个24点的网站http://www.24theory.com/solutions/allsolutions/,于是想起来把程序写写。考虑到中缀表达式有括号的麻烦,所以打算用后缀表达式处理。24点用后缀表达式的话,一共4个数字,3个运算符。假设数字用1表示,运算符用2表示。那么可能的计算方式就是类似11112221112221。。。但是这样随便列举出来的不一定是合法的后缀表达式。所以第一步,找出合法的包含4个数值,3个运算符的后缀表达式。bool check(int data[])
{ int len = 7; stack<int> suffix; for ... 阅读全文