Problem 2655 --Elementary data structures - Stack

2655: Elementary data structures - Stack

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $29$ 正确数量 $16$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 STL

Reverse Polish notation is a notation where every operator follows all of its operands. For example, an expression (1+2)*(5+4) in the conventional Polish notation can be represented as 1 2 + 5 4 + * in the Reverse Polish notation. One of advantages of the Reverse Polish notation is that it is parenthesis-free. 

Write a program which reads an expression in the Reverse Polish notation and prints the computational result.

An expression in the Reverse Polish notation is calculated using a stack. To evaluate the expression, the program should read symbols in order. If the symbol is an operand, the corresponding value should be pushed into the stack. On the other hand, if the symbols is an operator, the program should pop two elements from the stack, perform the corresponding operations, then push the result in to the stack. The program should repeat this operations.

An expression is given in a line. Two consequtive symbols (operand or operator) are separated by a space character.

You can assume that +, - and * are given as the operator and an operand is a positive integer less than 10^6

Print the computational result in a line.
1 2 +
3

2 ≤  the number of operands in the expression ≤  100

1 ≤  the number of operators in the expression ≤  99

-1 × 10^9 ≤ values in the stack ≤  10^9

推荐代码 查看2655 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] beholder 779077 2021-11-14 15:24:46
内存最少[$1124 $KB] beholder 779077 2021-11-14 15:24:46
第一AC AOJ大管家 338580 2018-12-05 21:35:08
第一挑战 AOJ大管家 338580 2018-12-05 21:35:08

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛