zoukankan      html  css  js  c++  java
  • 求整数数组中子数组最大的和

    团队成员:付亚飞  段兴林

      这次的结对项目是求整数数组中子数组最大的和,我们没能在课堂上按时完成题目,把纸上设计的程序运行了一下还存在错误,经过课下的修改能够实现功能了。

    public class  array
     
      {
     
      public static void main(String[] args)
     
        {
     
         int[]a={1 ,-2,3,-4,3,4,6,-2,4,-5};
     
         int max=maxsum(a);
     
        System.out.println("max="+max);
     
        }
     
         public static int maxsum(int a[])
     
        {
     
          int sum=0,max=0;
     
          for(int i=0;i<a.length;i++)
     
            {
     
              sum=sum+a[a.length-i-1];
     
              if(a[a.length-i-1]>0)
     
                if(sum>max)
     
                {
     
                  max=sum;
     
                }
     
               if(sum<0)
     
                {
     
                     sum=0;
     
                }
     
                      return max;
     
                  }
     
                }
     
     }    
     
     
  • 相关阅读:
    Lyndon Word & The Runs Theorem
    Codeforces 1477F. Nezzar and Chocolate Bars
    Codeforces Round #700 (Div.1)
    kubeadm 安装 k8s
    centos7更新阿里yum源
    CF1186 F. Vus the Cossack and a Graph
    CF1152 D. Neko and Aki's Prank
    CF803 C. Maximal GCD
    CF1180 B. Nick and Array
    CF1186 D. Vus the Cossack and Numbers
  • 原文地址:https://www.cnblogs.com/feiji/p/3591902.html
Copyright © 2011-2022 走看看