UVa 10700 Camel trading:计算表达式2014-07-29 synapse7 10700 - Camel tradingTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1641BackgroundAroud 800 A.D., El Mamum, Calif of Baghdad was presented the formula 1+2*3*4+5, which had its origin in the financial accounts of a camel transaction. The formula lacked parenthesis and was ambiguous. So, he decided to ask savants to provide him with a method to find which interpretation is the most advantageous for him, depending on whether is is buying or selling the camels.The ProblemYou are commissioned by El Mamum to write a program that determines the maximum and minimum possible interpretation of a parenthesis-less expression.InputThe input consists of an integer N, followed by N lines, each containing an expression. Each expression is composed of at most 12 numbers, each ranging between 1 and 20, and separated by the sum and product operators + and *.OutputFor each given expression, the output will echo a line with the corresponding maximal and minimal interpretations, following the format given in the sample output.Sample input3
1+2*3*4+5
4*18+14+7*10
3+11+4*1*13*12*8+3*3+8Sample outputThe maximum and minimum are 81 and 30.
The maximum and minimum are 1560 and 156.
The maximum and minimum are 339768 and 5023.水题。完整代码:
/*0.016s*/#include<cstdio>#include<cstring>typedef long long ll;ll mul[15], add[15];int main(){int n, mp, ap;ll max, min, num;char c;scanf("%d", &n);while (n--){memset(mul, 0, sizeof(mul));memset(add, 0, sizeof(add));c = "+";mp = 0, ap = -1;while (c != 10){scanf("%lld", &num);if (c == "+") mul[mp] += num, add[++ap] = num;else mul[++mp] = num, add[ap] *= num;scanf("%c", &c);}max = 1, min = 0;for (int i = 0; i <= mp; ++i) max *= mul[i];for (int i = 0; i <= ap; ++i) min += add[i];printf("The maximum and minimum are %lld and %lld.
", max, min);}return 0;}