10700-camel Trading
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=1641
Background
Aroud A.D., EL Mamum, Calif of Baghdad was presented the formula 1+2*3*4+5, which had it origin in the financial Unts of a camel transaction. The formula lacked parenthesis and was ambiguous. So, him decided to ask Savants to provide him with a and to find which interpretation are the most advantageous for him, Depending on whether are is buying or selling the camels.
The Problem
You are are commissioned by El Mamum to write a program that determines the maximum and minimum possible of a P Arenthesis-less expression.
Input
The input consists of an integer n, followed by n lines, each containing a expression. Each expression is composed in most numbers, each ranging between 1 and separated by the sum and product ope Rators + and *.
Output
For each given expression, the output would echo a line with the corresponding maximal and minimal interpretations NG the format given in the sample output.
Sample input
3
1+2*3*4+5
4*18+14+7*10
3+11+4*1*13*12*8+3*3+8
Sample output
The maximum and minimum are Bayi and 30.
The maximum and minimum are 1560 and 156.
The maximum and minimum are 339768 and 5023.
Water problem.
Complete code:
/*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!=)
{
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.\n", Max, Min);
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/