zoukankan      html  css  js  c++  java
  • UVA 10700 Camel trading

    UVA_10700

    我们可以猜到最大值一定是先算和后算积,最小值一定是先算积后算和,因为a*b+c<=a*(b+c)

    此外,这个题目数据有可能比较大,所以要采用long long int或者double来处理数据。

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


  • 相关阅读:
    ssh.sh_for_ubuntu1604
    ssh.sh_for_ubuntu1404
    ssh.sh_for_ubuntu1204
    ssh.sh_for_centos
    raw,cow,qcow,qcow2镜像的比较
    Oz 创建Windows2008R2镜像
    Oz 创建Ubuntu镜像
    Oz 创建Debian8镜像
    Oz 创建CentOS7镜像
    Oz 创建CentOS6镜像
  • 原文地址:https://www.cnblogs.com/staginner/p/2184729.html
Copyright © 2011-2022 走看看