TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

給定一個合法的 infix(中序)算術表達式,請將它轉換成等價的 postfix(後序)表達式。

表達式中的每個 token 以一個空白分隔。token 可能是非負整數、括號,或以下四種二元運算子:

  • +-
  • */

乘法與除法的優先順序高於加法與減法;相同優先順序由左到右計算。postfix 結果不包含括號。

本題只接受 C 語言提交。

Input Format

第一行有一個整數 n,表示下一行表達式的字元數(不包含換行字元)。

第二行是一個長度為 n 的合法 infix 表達式。

Output Format

輸出轉換後的 postfix 表達式,每個 token 以一個空白分隔,不要輸出行尾空白。

Sample Input 1

18
12 + 3 * ( 4 - 2 )

Sample Output 1

12 3 4 2 - * +

Hints

  • 1 <= n <= 10000
  • 所有數字都是 64-bit signed integer 範圍內的非負整數。
  • 不會出現一元正負號。

Problem Source

tioj/problem/infix-to-postfix

Subtasks

No. Testdata Range Score
1 0~2 100

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 65536 65536 1
1 1000 65536 65536 1
2 1000 65536 65536 1