LISA - Pocket Money
Young people spend a lot of money on things like sweets, music CDs, mobile phones and so on. But most young girls/boys have one problem: Their pocket money is not enough for all these jolly things. Little Lisa Listig is one of these poor girls with a small pocket money budget. Last month her pocket money lasted only one week. So she decided to enter into negotiations with her father. Her father Tomm - a mathematician - had an incredibly ingenious idea: He wrote down some fancy digits with operators (+,*) in between them on a sheet of paper and allowed Lisa to insert brackets. Then he declared that the result of that arithmetic expression is Lisa's new pocket money. Now it's Lisa's task to maximize her pocket money. As her father was surprised what a huge sum of money Lisa got for her result, he decided to minimize the result of the expression for his son Manfred. Now it's your task to calculate the results obtained by Lisa and her father.
The first line of input contains the number of testcases k ( k< 5000 ). Each of the following k lines consists of an arithemtic expression. This expression consists of numbers (0-9) seperated by one of the two operators '*' and '+'. There are no spaces between the characters. Each line contains less than 100 characters.
For each expression output the result obtained by Lisa and the result obtained by her father separated by one space. The results of the calculations are smaller than 264.
Input: 1 1+2*3+4*5 Output: 105 27
Two possible expressions for the first testcase:
105 = (1+2)*(3+4)*5 27 = 1+2*3+4*5
if there were no 0, would greedy solution work?
<No spoilers in the comments>Last edit: 2012-12-12 07:48:43
<No spoilers in the comments>Last edit: 2012-12-12 07:48:59
You needn't worry much about your solution's complexity (you have a time limit of 32 seconds). Test cases only require like 0.1 seconds though.
2+1*0*1+1 might be a tricky case for some approaches.
kennard, i believe the answer would be 22 0Last edit: 2011-06-09 04:19:25
Any tricky cases to look out for?
what is the answer for