UVa 10700 Camel Trading: Evaluating expressions

Source: Internet
Author: User
Tags expression min mul time limit

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/

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.