zoukankan      html  css  js  c++  java
  • UVa 11059 Maximum Product(简单枚举7.1)使用longlong,输出格式%lld

    这题数据最大18位,应该用Long long 粗心在几个地方(函数返回值,中间比较值max pro)用了Int,提交了好几次

    #include<stdio.h>
    
    long long func(int *a,int head,int rear){//一开始用了int 
        long long pro=a[head];//注意这里初值不能赋值为1 2
     0 0这个通不过 
        if(head==rear)
        return a[head];
        else 
        for(int i=head+1;i<=rear;i++)
        pro*=a[i];
        return pro;
    }
    
    int main(){
        //freopen("test.out","w",stdout);
        int n,count=1;
        long long pro;//一开始用int 细心啊 
        while(scanf("%d",&n)!=EOF){
            int a[n];
            long long max=0;
            for(int i=0;i<n;i++){
                scanf("%d",a+i);
            }
            for(int head=0;head<n;head++){
                for(int rear=head;rear<n;rear++){//bug?
                pro=func(a,head,rear);
                if(max<pro){
                max=pro;
                //printf("%d %d %d
    ",head,rear,max);    
                }
                }
            }
            
            if(max<0)
            max=0;
            printf("Case #%d: The maximum product is %lld.
    
    ",count++,max);
        } 
        return 0;
    } 
  • 相关阅读:
    mongoDB
    邮箱认证
    Django中开启事务的两种方式
    总结
    __new__和__init__和__call__方法理解
    jupyter
    text()和html()区别
    django模型中auto_now和auto_now_add的区别
    ajax嵌套陷阱
    模板内置函数(HTML)
  • 原文地址:https://www.cnblogs.com/lsj2020/p/5793131.html
Copyright © 2011-2022 走看看