UVa 10700 - Camel trading

10700 - Camel Trading

 * http://acm.uva.es/p/v107/10700.html

Summary
A greedy solution will solve this question. This question also requires some knowledge in parsing of the input.

Explanation
To find the maximum value, do the addition first, then the multiplication. Similiarly, to find the minimium value, do the multiplication first, then the addition.

Gotcha
Remember to use "long long" as 20^12 is bigger than 2^32. (Look at the sample input)

Input
4 1+2*3*4+5 4*18+14+7*10 3+11+4*1*13*12*8+3*3+8 20*20*20*20*20*20*20*20*20*20*20*20

Output
The maximum and minimum are 81 and 30. The maximum and minimum are 1560 and 156. The maximum and minimum are 339768 and 5023. The maximum and minimum are 37683200000000000 and 37683200000000000.