计算逆波兰式子:
有效的操作只有 +, -, *, /. 每一个输入不是一个整数就是一个操作符。
Some examples:
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9
["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
#include
#include
#include
using namespace std; const int Max=100; bool isInt(const string str) { if(str[0]=='+'||(str[0]=='-'&&str.size()==1)||str[0]=='*'||str[0]=='/') return false; else return true; } int toInt(string str) { int re=0; //cout<<"str: "<
&tokens) { double values[Max]={0}; int k=0; vector
oper; double result=0; for(int i=0;i
token(str,str+5); cout<
代码中用数组模拟类一个栈的操作。