English translate

Reverse Polish notation (or just RPN) by analogy with the related Polish notation, a prefix notation introduced in 1920 by the Polish mathematician Jan Łukasiewicz, is a mathematical notation wherein every operator follows all of its operands. It is also known as Postfix notation.

In Reverse Polish notation the operators follow their operands; for instance, to add three and four one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 − 4 + 5" in conventional infix notation would be written "3 4 − 5 +" in RPN: first subtract 4 from 3, then add 5 to that. An advantage of RPN is that it obviates the need for parentheses that are required by infix. While "3 − 4 * 5" can also be written "3 − (4 * 5)", that means something quite different from "(3 − 4) * 5", and only the parentheses disambiguate the two meanings. In postfix, the former would be written "3 4 5 * −", which unambiguously means "3 (4 5 *) −".

You were asked to design a simple RPN calculator, which will support the “+”, “-“, “*”, “/”(the absolute value of the divisor will not less then 10^-9) and “^”(power operator, if the base number b<=0, the exponential e must be a positive integer not greater than 10^9) operators. You can assume all the numbers during the calculation can fit into a double-precision floating point number.

In addition, our calculator has some memory. Each time we calculate an expression, the smallest number in the memory will be erased, and replace it with the value of the expression.

输入

The first line contains an integer n, which is the memory size of our calculator.

From the second line, we will give n numbers, which is the initial value of the memory. each line except last will have 10 numbers.

And then each line has a valid RPN expression we previously described, end with “=”, which is the command for calculation. Each term will no longer than 20 characters.

输出

For each expression, output the value of it in a line.
And then output an empty line to separate the two parts.
At last, output the all the numbers in memory, in increasing order, 10 numbers per line.

Each number should be formatted in scientific notation with 6 digits after decimal point and 2 digits of exponential, such like “%e” format string of printf() function in C. The numbers in a line should be separated by a space.

反向波兰表示法(或只是 RPN)与相关的波兰表示法(波兰数学家 Jan Łukasiewicz 于 1920 年引入的前缀表示法)类比,是一种数学表示法,其中每个运算符都遵循其所有操作数。它也称为后缀表示法。

在反向波兰表示法中,运算符遵循其操作数;例如,将三加四加一会写成“3 4 +”而不是“3 + 4”。如果有多个操作,则在其第二个操作数之后立即给出操作符;所以用传统中缀表示法写成“3 - 4 + 5”的表达式在 RPN 中会写成“3 4 - 5 +”:首先从 3 中减去 4,然后再加上 5。 RPN 的一个优点是它不需要中缀所需的括号。虽然“3 - 4 * 5”也可以写成“3 - (4 * 5)”,但这与“(3 - 4) * 5”的含义完全不同,只有括号消除了这两个含义的歧义。在后缀中,前者将写作“3 4 5 * -”,明确表示“3 (4 5 *) -”。

你被要求设计一个简单的RPN计算器,它将支持“+”、“-”、“*”、“/”(除数的绝对值不会小于10^-9)和“^”(幂运算符,如果基数 b<=0,则指数 e 必须是不大于 10^9) 运算符的正整数。您可以假设计算过程中的所有数字都可以放入双精度浮点数。

此外,我们的计算器还有一些内存。每次我们计算一个表达式时,内存中最小的数都会被擦除,并用表达式的值来代替。

输入
第一行包含一个整数 n,它是我们计算器的内存大小。


从第二行开始,我们将给出 n 个数字,这是内存的初始值。除最后一行外,每一行都有 10 个数字。


然后每一行都有一个我们之前描述的有效的RPN表达式,以“=”结尾,这是计算的命令。每个术语将不超过 20 个字符。

输出
对于每个表达式,在一行中输出它的值。
然后输出一个空行来分隔两部分。
最后,将内存中的所有数字按递增顺序输出,每行 10 个数字。

每个数字都应采用科学计数形式,小数点后 6 位,指数 2 位,如 C 中 printf() 函数的“%e”格式字符串。一行中的数字之间用空格隔开。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值