Uva_10700
We can guess that the maximum value must be calculated first and then the product, and the minimum value must be calculated first and then the sum.,BecauseA * B + C <= A * (B + C).
In addition, the data of this question may be relatively large, so we need to useLong long intOrDoubleTo process data.
# Include <stdio. h>
# Include < String . H>
# Include <ctype. h>
Char B [1000 ];
Double Stack [ 10000 ];
Int Main ()
{
Int I, J, K, T, Head, top;
Double D, Min, Max, temp;
Char Flag;
Scanf ( " % D " , & T );
While (T --)
{
Scanf ( " % S " , B );
K = strlen (B );
Head = Top = 0 ;
Min = 0.0 ;
B [k] = ' + ' ;
For (I = 0 ; I <= K; I ++)
If (! Isdigit (B [I])
{
Flag = B [I];
B [I] = ' \ 0 ' ;
Sscanf (& B [head], " % Lf " , & D );
B [I] = flag;
Stack [top ++] = D;
If (Flag = ' + ' )
{
Temp = 1.0 ;
While (Top)
{
Top --;
Temp * = stack [Top];
}
Min + = temp;
}
Head = I + 1 ;
}
Temp = 0.0 ;
Head = 0 ;
Max = 1.0 ;
B [k] = ' * ' ;
For (I = 0 ; I <= K; I ++)
If (! Isdigit (B [I])
{
Flag = B [I];
B [I] = ' \ 0 ' ;
Sscanf (& B [head], " % Lf " , & D );
Temp + = D;
If (Flag = ' * ' )
{
Max * = temp;
Temp = 0.0 ;
}
Head = I +1 ;
}
Printf ( " The maximum and minimum are %. 0f and %. 0f. \ n " , Max, min );
}
Return 0 ;
}