问题3788--Ambiguous Result

3788: Ambiguous Result

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

The ACM (Advanced Cosmos Monitor) recorded a set of messages transmitted by alien race ofSpace Invaders. Unfortunately, the antenna used for recording only handles lower frequenciesrepresenting numbers and two arithmetical operators in space-invaderian language, while allparentheses (corresponding to a high frequency) were lost.Since numbers are important for those 8-bit creatures, we really need to know what numberranges these messages belong to -- please, write a program that can do this for us!

输入

Input contains several legal arithmetical expressions, each expression on a separate line. Eachexpression consists only of non-negative integers xi (0 ≤ xi ≤ 100) and binary operators "+"and "*". The expression starts with a number, then the operators and numbers alternate, andthe last element is a number. Each expression contains P numbers (1 ≤ P ≤ 100) and P - 1operators. There are no parentheses, no other operators, no unary operator, etc.The last input expression is followed by a line containing the single word "END".

输出

For each input line (not counting the final END), output one line containing the minimum andmaximum values (separated by a single space) that are achievable by adding parentheses to theinput in a way that forms a legal expression and computing the result of that expression.For example, the minimum value for 2 + 1 ∗ 0 input is achieved by (2 + 1) ∗ 0 and the maximumvalue is achieved by 2 + (1 ∗ 0). Therefore, you should print "0 2".It is guaranteed that for any placement of parentheses, the value of each parenthesis will be lessthen 263. This means that also the maximal result will be between 0 and 263 - 1, inclusive.

样例输入 Copy

2+1*0
3+2*5+1*7+16
0
END

样例输出 Copy

02
36 690
0 0

来源/分类