程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> it-Expressions

it-Expressions

編輯:編程解疑
Expressions

問題描述 :
Have you taken the course named Data Structure? Did you pass it? If you do, you should know that a mathematical expression can be expressed as a tree and why. In this problem, you are given some expressions, and you are supposed to draw the tree.

The expressions are composed of these letters:
(1) ‘a’, ‘b’, …, ‘z’ : means an operand;
(2) ‘+’, ‘-’, ‘*’, ‘/’ : dyadic operator, means plus sign, subtraction sign, multiplication sign and division sign;
(3) ‘-’ : monadic operator, means negative sign;
(4) ‘(‘, ‘)’ : used in pairs to alter priority.

輸入:

Input consists of multiple expressions each on a line (not exceed 50 letters). You should proceed to the end of file.
輸出:

For each expression, You should draw a tree that can express it, following the styles indicated in the sample output.

Note that the ‘#’ in the sample are supposed to tell you that there are spaces at the back of some lines, and you should ignore it in your output.

樣例輸入:

a+b+c
(a-a)*b+(-c)
樣例輸出:

  • #
    • c# a b #
      • #
  • - #
    • b c# a a #

最佳回答:


http://www.acmerblog.com/hdu-1855-Expressions-2842/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved