zoukankan      html  css  js  c++  java
  • HDU OJ Max sum 题目1003

    

    #include <iostream>
    #include<stdio.h>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
        int t;
        scanf("%d",&t);
        for(int i=0;i<t;i++)
        {
            int n;
            scanf("%d",&n);
            int sum=0,max=-99999;
            int curhead=1,rear=1,head=1;
            for(int j=0;j<n;j++)
            {
                int temp;
                scanf("%d",&temp);
                if(sum<0)//小于零  说明開始加的是负数
                {
                    curhead=j+1;//又一次计算开头元素的位置
                    sum=temp;

                }else//假设大于等于0  就加上temp
                {
                    sum+=temp;
                }
                if(sum>max)//假设sum超过max   又一次记录max  计算结尾元素的位置
                {
                    rear=j+1;
                    head=curhead;
                    max=sum;
                }
            }
            printf("Case %d: ",i+1);
            printf("%d %d %d ",max,head,rear);
            if(i!=t-1) printf(" ");
        }
    }

  • 相关阅读:
    通过IDEA创建SpringMVC项目记录
    开发问题总结
    idea控制台乱码解决
    java获取文件是否文件夹
    oralce优化文章
    乱码踩坑记录
    oracle关于左连接失效的一些问题
    volatile关键字
    postman body formdata和xwwwformurlencoded区别
    [转][C#]ScottPlot
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6877127.html
Copyright © 2011-2022 走看看