Код: Выделить всё
3+4*2/(1-5)^2^3
Код: Выделить всё
342*15-23^^/+
Код: Выделить всё
sin(2*x^2+6)-(cos(x)/(1-x))
Код: Выделить всё
std::string ParseExpression(const std::string &expr) {
std::string ops = "-+/*^";
std::stringstream output;
std::stack stack;
typedef std::string::const_iterator StringIterator;
for (StringIterator TOKEN = expr.cbegin(), END = expr.cend(); TOKEN != END; ++TOKEN) {
const char c = *TOKEN;
size_t idx = ops.find(c);
if (idx != std::string::npos) {
if (stack.empty()) {
stack.push(idx);
}
else {
while (!stack.empty()) {
int prec2 = stack.top() / 2;
int prec1 = idx / 2;
if (prec2 > prec1 || (prec2 == prec1 && c != '^')) {
output
Подробнее здесь: [url]https://stackoverflow.com/questions/24279027/usage-of-functions-with-rpn-form[/url]
Мобильная версия