Ultraviolet A 10700 camel trading

Source: Internet
Author: User

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 ;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.