嗯......如何评价公式? [英] ummm...... how to evaluate the formulae??

查看:72
本文介绍了嗯......如何评价公式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想写一个程序来评估一个公式,

我应该使用什么样的算法?


例如,

输入:

(2 + 3)*(3/4)+ 6-8


如何处理括号?

需要使用堆栈吗?


Thx .......



?_?

if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??

Thx.......


?_?

推荐答案



Mars写道:

Mars wrote:
如果我想写一个程序评估公式,我应该使用什么样的算法?

例如,
输入:
(2 + 3)*(3/4) + 6-8
如何处理括号?
需要使用堆栈?
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??




你可以转换代数表达式反向抛光表示法。

尝试搜索反向抛光表示法。

计算表达式和括号非常有效。

尝试 http://en.wikipedia.org/wiki/Reverse_Polish_notation



You can convert the algebraic expression to reverse polish notation.
Try searching for reverse polish notation. It is very effective with
computational expressions and parenthesis.
Try http://en.wikipedia.org/wiki/Reverse_Polish_notation


----- BEGIN PGP签名消息-----

哈希:SHA1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mars wrote:
如果我想写一个程序来评估一个公式,我应该使用什么样的算法?

例如,
输入:
(2 + 3)*(3/4)+6 -8


Google forrecursive descent parser

如何处理括号?


这是解析器的作用部分。

需要使用堆栈吗?


也许吧。或者不是,因为你的实现需要。

Thx .......


?_?
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8
Google for "recursive descent parser"
how to deal with the brackets??
That''s part of what the parser does.
need to use stacks??
Perhaps. Or not, as your implementation requires.
Thx.......


?_?



- -


Lew Pitcher,企业数据系统IT专家

企业技术解决方案,道明银行金融集团


(这里表达的意见是我自己的,不是我雇主的意见)

-----开始PGP签名-----

版本:GnuPG v1.2.4(MingW32)

iD8DBQFCE1wnagVFX4UWr64RAmueAKC7pvDB + wDo3KYuoTRUE3 Vnb5y4vwCgv3iE

lWW1zW5Dy21NDd / V9dE7DTw =

= yl + Y

-----结束PGP SIGNATURE -----


- --

Lew Pitcher, IT Specialist, Enterprise Data Systems
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer''s)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFCE1wnagVFX4UWr64RAmueAKC7pvDB+wDo3KYuoTRUE3 Vnb5y4vwCgv3iE
lWW1zW5Dy21NDd/V9dE7DTw=
=yl+Y
-----END PGP SIGNATURE-----


Steven提到:
Mars写道:
Mars wrote:
如果我想编写一个程序来评估公式,我应该使用什么样的算法?

例如,
输入:
(2 + 3)*(3/4)+ 6-8
如何处理括号?
需要使用堆栈?
if I want to write a program to evaluate a formulae,
what kind of algorithm should I use??

for example,
input:
(2+3)*(3/4)+6-8

how to deal with the brackets??
need to use stacks??



您可以转换alge用反向抛光表示法的braic表达式。
尝试搜索反向抛光表示法。使用
计算表达式和括号非常有效。
尝试 http ://en.wikipedia.org/wiki/Reverse_Polish_notation



icic,

所以如果我输入

1 + 3 * 4 + 2


它是

1 3 4 * + 2 +


对吗? ?


icic,
so if I enters
1+3*4+2

it is
1 3 4 * + 2 +

right??


这篇关于嗯......如何评价公式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆